From 407594566874462af36fd6bb4c9f89788341a8bd Mon Sep 17 00:00:00 2001 From: Bastien Chanot Date: Wed, 27 May 2026 05:13:35 +0200 Subject: [PATCH] fix(pdf): logo on all pages, clickable links, ZenQuality logo, higher separator - Header logo centered between practitioner/animal text on every page - Added clickable link annotations (faunosteo.com, zenquality.fr, Instagram) - Bundled ZenQuality SVG logo at public/brand/zenquality-logo.svg - Footer separator moved above logo area - Removed isFirstPage gating on header logo Co-Authored-By: Claude Opus 4.6 (1M context) --- src/pdf/export.ts | 7 +--- src/pdf/render/conclusionPage.ts | 3 +- src/pdf/render/footer.ts | 64 +++++++++++++++++++++++++------ src/pdf/render/header.ts | 44 ++++++++++++--------- src/pdf/render/linkAnnotation.ts | 35 +++++++++++++++++ src/pdf/render/observationPage.ts | 3 +- 6 files changed, 115 insertions(+), 41 deletions(-) create mode 100644 src/pdf/render/linkAnnotation.ts diff --git a/src/pdf/export.ts b/src/pdf/export.ts index 7ac59f99..3f546dbf 100644 --- a/src/pdf/export.ts +++ b/src/pdf/export.ts @@ -131,15 +131,10 @@ export async function exportReportToPdf( zoneLabels, findingsTree, locale, - i === 0, headerAssets, ) } - await addConclusionPage( - pdfDoc, report, fonts, locale, - totalObs === 0, - headerAssets, - ) + await addConclusionPage(pdfDoc, report, fonts, locale, headerAssets) const pages = pdfDoc.getPages() const footerAssets = { logoPng: logoPdfImage, zqLogoPng: zqLogoPdfImage } diff --git a/src/pdf/render/conclusionPage.ts b/src/pdf/render/conclusionPage.ts index c00656a9..d7ffab25 100644 --- a/src/pdf/render/conclusionPage.ts +++ b/src/pdf/render/conclusionPage.ts @@ -42,7 +42,6 @@ export async function addConclusionPage( report: Report, fonts: EmbeddedFonts, locale: Locale, - isFirstPage: boolean, headerAssets: HeaderAssets, ): Promise { const dict = getDict(locale) @@ -50,7 +49,7 @@ export async function addConclusionPage( const { width, height } = page.getSize() const max = width - MARGIN_X * 2 - drawHeader(page, report, fonts, locale, isFirstPage, headerAssets) + drawHeader(page, report, fonts, locale, headerAssets) const eyebrowY = height - EYEBROW_Y_OFFSET const titleY = height - TITLE_Y_OFFSET diff --git a/src/pdf/render/footer.ts b/src/pdf/render/footer.ts index a515bd6c..a140f805 100644 --- a/src/pdf/render/footer.ts +++ b/src/pdf/render/footer.ts @@ -2,10 +2,10 @@ import { rgb, type PDFPage, type PDFImage } from 'pdf-lib' import type { EmbeddedFonts } from '@/pdf/fonts' import type { Locale } from '@/i18n/types' import { getDict } from '@/i18n' +import { addLinkAnnotation } from './linkAnnotation' const MARGIN_X = 36 const FOOTER_BASE_Y = 20 -const SEPARATOR_Y = 48 const LINE_HEIGHT = 12 const FONT_SIZE = 8 @@ -27,16 +27,17 @@ export function drawFooter( const muted = rgb(0.42, 0.39, 0.35) const accent = rgb(0.28, 0.56, 0.42) - page.drawLine({ - start: { x: MARGIN_X, y: SEPARATOR_Y }, - end: { x: width - MARGIN_X, y: SEPARATOR_Y }, - thickness: 0.5, - color: rgb(0.85, 0.83, 0.8), - }) - const logoW = 60 const logoH = 23 const topRowY = FOOTER_BASE_Y + LINE_HEIGHT + 2 + const separatorY = topRowY + logoH + 6 + + page.drawLine({ + start: { x: MARGIN_X, y: separatorY }, + end: { x: width - MARGIN_X, y: separatorY }, + thickness: 0.5, + color: rgb(0.85, 0.83, 0.8), + }) if (assets.logoPng) { page.drawImage(assets.logoPng, { @@ -45,15 +46,31 @@ export function drawFooter( width: logoW, height: logoH, }) + addLinkAnnotation(page, { + x: MARGIN_X, + y: topRowY, + width: logoW, + height: logoH, + url: 'https://faunosteo.com', + }) } const siteUrl = 'faunosteo.com' + const siteUrlX = MARGIN_X + (assets.logoPng ? logoW + 4 : 0) + const siteUrlW = fonts.bodyRegular.widthOfTextAtSize(siteUrl, FONT_SIZE) page.drawText(siteUrl, { - x: MARGIN_X + (assets.logoPng ? logoW + 4 : 0), + x: siteUrlX, y: topRowY + 6, size: FONT_SIZE, font: fonts.bodyRegular, color: accent, }) + addLinkAnnotation(page, { + x: siteUrlX, + y: topRowY + 4, + width: siteUrlW, + height: FONT_SIZE + 4, + url: 'https://faunosteo.com', + }) const poweredLabel = `${dict['footer.powered_by']} ` const poweredLabelW = fonts.bodyRegular.widthOfTextAtSize(poweredLabel, FONT_SIZE) @@ -73,21 +90,36 @@ export function drawFooter( font: fonts.bodyRegular, color: muted, }) + const zqX = poweredX + poweredLabelW if (assets.zqLogoPng) { page.drawImage(assets.zqLogoPng, { - x: poweredX + poweredLabelW, + x: zqX, y: topRowY + 2, width: zqLogoW, height: zqLogoH, }) + addLinkAnnotation(page, { + x: zqX, + y: topRowY + 2, + width: zqLogoW, + height: zqLogoH, + url: 'https://zenquality.fr', + }) } else { page.drawText(zqFallback, { - x: poweredX + poweredLabelW, + x: zqX, y: topRowY + 6, size: FONT_SIZE, font: fonts.bodyRegular, color: accent, }) + addLinkAnnotation(page, { + x: zqX, + y: topRowY + 4, + width: zqFallbackW, + height: FONT_SIZE + 4, + url: 'https://zenquality.fr', + }) } const partnerText = `${dict['footer.in_partnership']} Paws iin Harmony` @@ -102,13 +134,21 @@ export function drawFooter( const instagramHandle = '@paws.iin.harmony' const handleW = fonts.bodyRegular.widthOfTextAtSize(instagramHandle, FONT_SIZE) + const handleX = width - MARGIN_X - handleW page.drawText(instagramHandle, { - x: width - MARGIN_X - handleW, + x: handleX, y: FOOTER_BASE_Y + 2, size: FONT_SIZE, font: fonts.bodyRegular, color: accent, }) + addLinkAnnotation(page, { + x: handleX, + y: FOOTER_BASE_Y, + width: handleW, + height: FONT_SIZE + 4, + url: 'https://www.instagram.com/paws.iin.harmony', + }) const pageText = `${pageNumber} / ${totalPages}` const pageW = fonts.bodyRegular.widthOfTextAtSize(pageText, FONT_SIZE) diff --git a/src/pdf/render/header.ts b/src/pdf/render/header.ts index 365df3e1..20d0b6f1 100644 --- a/src/pdf/render/header.ts +++ b/src/pdf/render/header.ts @@ -4,11 +4,12 @@ import type { Report } from '@/domain/schema/report' import type { Locale } from '@/i18n/types' import { getDict } from '@/i18n' import { formatDate } from '@/lib/dates' +import { addLinkAnnotation } from './linkAnnotation' const MARGIN_X = 36 const TOP_Y = 800 -const LOGO_WIDTH = 120 -const LOGO_HEIGHT = 46 +const LOGO_WIDTH = 100 +const LOGO_HEIGHT = 38 export interface HeaderAssets { logoPng: PDFImage | null @@ -19,7 +20,6 @@ export function drawHeader( report: Report, fonts: EmbeddedFonts, locale: Locale, - isFirstPage: boolean, assets: HeaderAssets, ): void { const dict = getDict(locale) @@ -27,19 +27,7 @@ export function drawHeader( const ink = rgb(0.12, 0.11, 0.09) const muted = rgb(0.42, 0.39, 0.35) - let contentTopY = TOP_Y - - if (isFirstPage && assets.logoPng) { - const logoX = (width - LOGO_WIDTH) / 2 - const logoY = TOP_Y - LOGO_HEIGHT + 20 - page.drawImage(assets.logoPng, { - x: logoX, - y: logoY, - width: LOGO_WIDTH, - height: LOGO_HEIGHT, - }) - contentTopY = logoY - 16 - } + const y = TOP_Y const left = [ report.practitioner.name, @@ -50,7 +38,6 @@ export function drawHeader( : undefined, ].filter(Boolean) as string[] - const y = contentTopY left.forEach((line, i) => { page.drawText(line, { x: MARGIN_X, @@ -61,6 +48,24 @@ export function drawHeader( }) }) + if (assets.logoPng) { + const logoX = (width - LOGO_WIDTH) / 2 + const logoY = y - LOGO_HEIGHT + 10 + page.drawImage(assets.logoPng, { + x: logoX, + y: logoY, + width: LOGO_WIDTH, + height: LOGO_HEIGHT, + }) + addLinkAnnotation(page, { + x: logoX, + y: logoY, + width: LOGO_WIDTH, + height: LOGO_HEIGHT, + url: 'https://faunosteo.com', + }) + } + const animalLine = [ report.animal.name, report.animal.breed ? `(${report.animal.breed})` : '', @@ -87,9 +92,10 @@ export function drawHeader( }) }) + const separatorY = y - Math.max(left.length * 12, LOGO_HEIGHT) - 8 page.drawLine({ - start: { x: MARGIN_X, y: y - 40 }, - end: { x: width - MARGIN_X, y: y - 40 }, + start: { x: MARGIN_X, y: separatorY }, + end: { x: width - MARGIN_X, y: separatorY }, thickness: 0.5, color: muted, }) diff --git a/src/pdf/render/linkAnnotation.ts b/src/pdf/render/linkAnnotation.ts new file mode 100644 index 00000000..19afeb5f --- /dev/null +++ b/src/pdf/render/linkAnnotation.ts @@ -0,0 +1,35 @@ +import { PDFName, PDFArray, PDFString, type PDFPage } from 'pdf-lib' + +export interface LinkRect { + x: number + y: number + width: number + height: number + url: string +} + +export function addLinkAnnotation(page: PDFPage, rect: LinkRect): void { + const context = page.doc.context + + const actionDict = context.obj({ + Type: 'Action', + S: 'URI', + URI: PDFString.of(rect.url), + }) + + const annotDict = context.obj({ + Type: 'Annot', + Subtype: 'Link', + Rect: [rect.x, rect.y, rect.x + rect.width, rect.y + rect.height], + Border: [0, 0, 0], + A: actionDict, + }) + + const annots = page.node.lookup(PDFName.of('Annots'), PDFArray) + if (annots) { + annots.push(context.register(annotDict)) + } else { + const arr = context.obj([context.register(annotDict)]) + page.node.set(PDFName.of('Annots'), arr) + } +} diff --git a/src/pdf/render/observationPage.ts b/src/pdf/render/observationPage.ts index a5a80df8..03c6f55b 100644 --- a/src/pdf/render/observationPage.ts +++ b/src/pdf/render/observationPage.ts @@ -275,13 +275,12 @@ export async function addObservationPage( zoneLabels: Map, findingsTree: SpeciesFindings | null, locale: Locale, - isFirstPage: boolean, headerAssets: HeaderAssets, ): Promise { const dict = getDict(locale) const page = pdfDoc.addPage(PageSizes.A4) const { width, height } = page.getSize() - drawHeader(page, report, fonts, locale, isFirstPage, headerAssets) + drawHeader(page, report, fonts, locale, headerAssets) const eyebrowY = height - EYEBROW_Y_OFFSET const titleY = height - TITLE_Y_OFFSET