Files
faunosteo/src/pdf/render/footer.ts
T
Bastien ChanotandClaude Opus 4.6 33a7f47fdf feat(pdf): add branding to PDF exports (header logo + footer links)
Header: centered Faunosteo logo on first page.
Footer: Faunosteo logo + faunosteo.com, ZenQuality logo + "Powered by",
Paws iin Harmony + @instagram handle, page numbers. Removed export date
and plain-text site name from footer.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-27 05:03:15 +02:00

123 lines
3.1 KiB
TypeScript

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'
const MARGIN_X = 36
const FOOTER_BASE_Y = 20
const SEPARATOR_Y = 48
const LINE_HEIGHT = 12
const FONT_SIZE = 8
export interface FooterAssets {
logoPng: PDFImage | null
zqLogoPng: PDFImage | null
}
export function drawFooter(
page: PDFPage,
fonts: EmbeddedFonts,
pageNumber: number,
totalPages: number,
locale: Locale,
assets: FooterAssets,
): void {
const dict = getDict(locale)
const { width } = page.getSize()
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
if (assets.logoPng) {
page.drawImage(assets.logoPng, {
x: MARGIN_X,
y: topRowY,
width: logoW,
height: logoH,
})
}
const siteUrl = 'faunosteo.com'
page.drawText(siteUrl, {
x: MARGIN_X + (assets.logoPng ? logoW + 4 : 0),
y: topRowY + 6,
size: FONT_SIZE,
font: fonts.bodyRegular,
color: accent,
})
const poweredLabel = `${dict['footer.powered_by']} `
const poweredLabelW = fonts.bodyRegular.widthOfTextAtSize(poweredLabel, FONT_SIZE)
const zqLogoW = 50
const zqLogoH = 12
const zqFallback = 'zenquality.fr'
const zqFallbackW = fonts.bodyRegular.widthOfTextAtSize(zqFallback, FONT_SIZE)
const poweredBlockW = assets.zqLogoPng
? poweredLabelW + zqLogoW
: poweredLabelW + zqFallbackW
const poweredX = (width - poweredBlockW) / 2
page.drawText(poweredLabel, {
x: poweredX,
y: topRowY + 6,
size: FONT_SIZE,
font: fonts.bodyRegular,
color: muted,
})
if (assets.zqLogoPng) {
page.drawImage(assets.zqLogoPng, {
x: poweredX + poweredLabelW,
y: topRowY + 2,
width: zqLogoW,
height: zqLogoH,
})
} else {
page.drawText(zqFallback, {
x: poweredX + poweredLabelW,
y: topRowY + 6,
size: FONT_SIZE,
font: fonts.bodyRegular,
color: accent,
})
}
const partnerText = `${dict['footer.in_partnership']} Paws iin Harmony`
const partnerW = fonts.bodyRegular.widthOfTextAtSize(partnerText, FONT_SIZE)
page.drawText(partnerText, {
x: width - MARGIN_X - partnerW,
y: topRowY + 6,
size: FONT_SIZE,
font: fonts.bodyRegular,
color: muted,
})
const instagramHandle = '@paws.iin.harmony'
const handleW = fonts.bodyRegular.widthOfTextAtSize(instagramHandle, FONT_SIZE)
page.drawText(instagramHandle, {
x: width - MARGIN_X - handleW,
y: FOOTER_BASE_Y + 2,
size: FONT_SIZE,
font: fonts.bodyRegular,
color: accent,
})
const pageText = `${pageNumber} / ${totalPages}`
const pageW = fonts.bodyRegular.widthOfTextAtSize(pageText, FONT_SIZE)
page.drawText(pageText, {
x: (width - pageW) / 2,
y: FOOTER_BASE_Y + 2,
size: FONT_SIZE,
font: fonts.bodyRegular,
color: muted,
})
}