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) <noreply@anthropic.com>
This commit is contained in:
1 parent
33a7f47fdf
commit
4075945668
6 files changed
+115
-41
No files matched your search
+1
-6
@@ -131,15 +131,10 @@ export async function exportReportToPdf(
|
|||||||
zoneLabels,
|
zoneLabels,
|
||||||
findingsTree,
|
findingsTree,
|
||||||
locale,
|
locale,
|
||||||
i === 0,
|
|
||||||
headerAssets,
|
headerAssets,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
await addConclusionPage(
|
await addConclusionPage(pdfDoc, report, fonts, locale, headerAssets)
|
||||||
pdfDoc, report, fonts, locale,
|
|
||||||
totalObs === 0,
|
|
||||||
headerAssets,
|
|
||||||
)
|
|
||||||
|
|
||||||
const pages = pdfDoc.getPages()
|
const pages = pdfDoc.getPages()
|
||||||
const footerAssets = { logoPng: logoPdfImage, zqLogoPng: zqLogoPdfImage }
|
const footerAssets = { logoPng: logoPdfImage, zqLogoPng: zqLogoPdfImage }
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ export async function addConclusionPage(
|
|||||||
report: Report,
|
report: Report,
|
||||||
fonts: EmbeddedFonts,
|
fonts: EmbeddedFonts,
|
||||||
locale: Locale,
|
locale: Locale,
|
||||||
isFirstPage: boolean,
|
|
||||||
headerAssets: HeaderAssets,
|
headerAssets: HeaderAssets,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const dict = getDict(locale)
|
const dict = getDict(locale)
|
||||||
@@ -50,7 +49,7 @@ export async function addConclusionPage(
|
|||||||
const { width, height } = page.getSize()
|
const { width, height } = page.getSize()
|
||||||
const max = width - MARGIN_X * 2
|
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 eyebrowY = height - EYEBROW_Y_OFFSET
|
||||||
const titleY = height - TITLE_Y_OFFSET
|
const titleY = height - TITLE_Y_OFFSET
|
||||||
|
|||||||
+52
-12
@@ -2,10 +2,10 @@ import { rgb, type PDFPage, type PDFImage } from 'pdf-lib'
|
|||||||
import type { EmbeddedFonts } from '@/pdf/fonts'
|
import type { EmbeddedFonts } from '@/pdf/fonts'
|
||||||
import type { Locale } from '@/i18n/types'
|
import type { Locale } from '@/i18n/types'
|
||||||
import { getDict } from '@/i18n'
|
import { getDict } from '@/i18n'
|
||||||
|
import { addLinkAnnotation } from './linkAnnotation'
|
||||||
|
|
||||||
const MARGIN_X = 36
|
const MARGIN_X = 36
|
||||||
const FOOTER_BASE_Y = 20
|
const FOOTER_BASE_Y = 20
|
||||||
const SEPARATOR_Y = 48
|
|
||||||
const LINE_HEIGHT = 12
|
const LINE_HEIGHT = 12
|
||||||
const FONT_SIZE = 8
|
const FONT_SIZE = 8
|
||||||
|
|
||||||
@@ -27,16 +27,17 @@ export function drawFooter(
|
|||||||
const muted = rgb(0.42, 0.39, 0.35)
|
const muted = rgb(0.42, 0.39, 0.35)
|
||||||
const accent = rgb(0.28, 0.56, 0.42)
|
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 logoW = 60
|
||||||
const logoH = 23
|
const logoH = 23
|
||||||
const topRowY = FOOTER_BASE_Y + LINE_HEIGHT + 2
|
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) {
|
if (assets.logoPng) {
|
||||||
page.drawImage(assets.logoPng, {
|
page.drawImage(assets.logoPng, {
|
||||||
@@ -45,15 +46,31 @@ export function drawFooter(
|
|||||||
width: logoW,
|
width: logoW,
|
||||||
height: logoH,
|
height: logoH,
|
||||||
})
|
})
|
||||||
|
addLinkAnnotation(page, {
|
||||||
|
x: MARGIN_X,
|
||||||
|
y: topRowY,
|
||||||
|
width: logoW,
|
||||||
|
height: logoH,
|
||||||
|
url: 'https://faunosteo.com',
|
||||||
|
})
|
||||||
}
|
}
|
||||||
const siteUrl = '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, {
|
page.drawText(siteUrl, {
|
||||||
x: MARGIN_X + (assets.logoPng ? logoW + 4 : 0),
|
x: siteUrlX,
|
||||||
y: topRowY + 6,
|
y: topRowY + 6,
|
||||||
size: FONT_SIZE,
|
size: FONT_SIZE,
|
||||||
font: fonts.bodyRegular,
|
font: fonts.bodyRegular,
|
||||||
color: accent,
|
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 poweredLabel = `${dict['footer.powered_by']} `
|
||||||
const poweredLabelW = fonts.bodyRegular.widthOfTextAtSize(poweredLabel, FONT_SIZE)
|
const poweredLabelW = fonts.bodyRegular.widthOfTextAtSize(poweredLabel, FONT_SIZE)
|
||||||
@@ -73,21 +90,36 @@ export function drawFooter(
|
|||||||
font: fonts.bodyRegular,
|
font: fonts.bodyRegular,
|
||||||
color: muted,
|
color: muted,
|
||||||
})
|
})
|
||||||
|
const zqX = poweredX + poweredLabelW
|
||||||
if (assets.zqLogoPng) {
|
if (assets.zqLogoPng) {
|
||||||
page.drawImage(assets.zqLogoPng, {
|
page.drawImage(assets.zqLogoPng, {
|
||||||
x: poweredX + poweredLabelW,
|
x: zqX,
|
||||||
y: topRowY + 2,
|
y: topRowY + 2,
|
||||||
width: zqLogoW,
|
width: zqLogoW,
|
||||||
height: zqLogoH,
|
height: zqLogoH,
|
||||||
})
|
})
|
||||||
|
addLinkAnnotation(page, {
|
||||||
|
x: zqX,
|
||||||
|
y: topRowY + 2,
|
||||||
|
width: zqLogoW,
|
||||||
|
height: zqLogoH,
|
||||||
|
url: 'https://zenquality.fr',
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
page.drawText(zqFallback, {
|
page.drawText(zqFallback, {
|
||||||
x: poweredX + poweredLabelW,
|
x: zqX,
|
||||||
y: topRowY + 6,
|
y: topRowY + 6,
|
||||||
size: FONT_SIZE,
|
size: FONT_SIZE,
|
||||||
font: fonts.bodyRegular,
|
font: fonts.bodyRegular,
|
||||||
color: accent,
|
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`
|
const partnerText = `${dict['footer.in_partnership']} Paws iin Harmony`
|
||||||
@@ -102,13 +134,21 @@ export function drawFooter(
|
|||||||
|
|
||||||
const instagramHandle = '@paws.iin.harmony'
|
const instagramHandle = '@paws.iin.harmony'
|
||||||
const handleW = fonts.bodyRegular.widthOfTextAtSize(instagramHandle, FONT_SIZE)
|
const handleW = fonts.bodyRegular.widthOfTextAtSize(instagramHandle, FONT_SIZE)
|
||||||
|
const handleX = width - MARGIN_X - handleW
|
||||||
page.drawText(instagramHandle, {
|
page.drawText(instagramHandle, {
|
||||||
x: width - MARGIN_X - handleW,
|
x: handleX,
|
||||||
y: FOOTER_BASE_Y + 2,
|
y: FOOTER_BASE_Y + 2,
|
||||||
size: FONT_SIZE,
|
size: FONT_SIZE,
|
||||||
font: fonts.bodyRegular,
|
font: fonts.bodyRegular,
|
||||||
color: accent,
|
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 pageText = `${pageNumber} / ${totalPages}`
|
||||||
const pageW = fonts.bodyRegular.widthOfTextAtSize(pageText, FONT_SIZE)
|
const pageW = fonts.bodyRegular.widthOfTextAtSize(pageText, FONT_SIZE)
|
||||||
|
|||||||
+25
-19
@@ -4,11 +4,12 @@ import type { Report } from '@/domain/schema/report'
|
|||||||
import type { Locale } from '@/i18n/types'
|
import type { Locale } from '@/i18n/types'
|
||||||
import { getDict } from '@/i18n'
|
import { getDict } from '@/i18n'
|
||||||
import { formatDate } from '@/lib/dates'
|
import { formatDate } from '@/lib/dates'
|
||||||
|
import { addLinkAnnotation } from './linkAnnotation'
|
||||||
|
|
||||||
const MARGIN_X = 36
|
const MARGIN_X = 36
|
||||||
const TOP_Y = 800
|
const TOP_Y = 800
|
||||||
const LOGO_WIDTH = 120
|
const LOGO_WIDTH = 100
|
||||||
const LOGO_HEIGHT = 46
|
const LOGO_HEIGHT = 38
|
||||||
|
|
||||||
export interface HeaderAssets {
|
export interface HeaderAssets {
|
||||||
logoPng: PDFImage | null
|
logoPng: PDFImage | null
|
||||||
@@ -19,7 +20,6 @@ export function drawHeader(
|
|||||||
report: Report,
|
report: Report,
|
||||||
fonts: EmbeddedFonts,
|
fonts: EmbeddedFonts,
|
||||||
locale: Locale,
|
locale: Locale,
|
||||||
isFirstPage: boolean,
|
|
||||||
assets: HeaderAssets,
|
assets: HeaderAssets,
|
||||||
): void {
|
): void {
|
||||||
const dict = getDict(locale)
|
const dict = getDict(locale)
|
||||||
@@ -27,19 +27,7 @@ export function drawHeader(
|
|||||||
const ink = rgb(0.12, 0.11, 0.09)
|
const ink = rgb(0.12, 0.11, 0.09)
|
||||||
const muted = rgb(0.42, 0.39, 0.35)
|
const muted = rgb(0.42, 0.39, 0.35)
|
||||||
|
|
||||||
let contentTopY = TOP_Y
|
const y = 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 left = [
|
const left = [
|
||||||
report.practitioner.name,
|
report.practitioner.name,
|
||||||
@@ -50,7 +38,6 @@ export function drawHeader(
|
|||||||
: undefined,
|
: undefined,
|
||||||
].filter(Boolean) as string[]
|
].filter(Boolean) as string[]
|
||||||
|
|
||||||
const y = contentTopY
|
|
||||||
left.forEach((line, i) => {
|
left.forEach((line, i) => {
|
||||||
page.drawText(line, {
|
page.drawText(line, {
|
||||||
x: MARGIN_X,
|
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 = [
|
const animalLine = [
|
||||||
report.animal.name,
|
report.animal.name,
|
||||||
report.animal.breed ? `(${report.animal.breed})` : '',
|
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({
|
page.drawLine({
|
||||||
start: { x: MARGIN_X, y: y - 40 },
|
start: { x: MARGIN_X, y: separatorY },
|
||||||
end: { x: width - MARGIN_X, y: y - 40 },
|
end: { x: width - MARGIN_X, y: separatorY },
|
||||||
thickness: 0.5,
|
thickness: 0.5,
|
||||||
color: muted,
|
color: muted,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -275,13 +275,12 @@ export async function addObservationPage(
|
|||||||
zoneLabels: Map<string, ZoneLabelPair>,
|
zoneLabels: Map<string, ZoneLabelPair>,
|
||||||
findingsTree: SpeciesFindings | null,
|
findingsTree: SpeciesFindings | null,
|
||||||
locale: Locale,
|
locale: Locale,
|
||||||
isFirstPage: boolean,
|
|
||||||
headerAssets: HeaderAssets,
|
headerAssets: HeaderAssets,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const dict = getDict(locale)
|
const dict = getDict(locale)
|
||||||
const page = pdfDoc.addPage(PageSizes.A4)
|
const page = pdfDoc.addPage(PageSizes.A4)
|
||||||
const { width, height } = page.getSize()
|
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 eyebrowY = height - EYEBROW_Y_OFFSET
|
||||||
const titleY = height - TITLE_Y_OFFSET
|
const titleY = height - TITLE_Y_OFFSET
|
||||||
|
|||||||
Reference in new issue
Block a user