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>
This commit is contained in:
1 parent
c853c681f9
commit
33a7f47fdf
7 files changed
+314
-21
No files matched your search
+102
-12
@@ -1,12 +1,18 @@
|
||||
import { rgb, type PDFPage } from 'pdf-lib'
|
||||
import { rgb, type PDFPage, type PDFImage } from 'pdf-lib'
|
||||
import type { EmbeddedFonts } from '@/pdf/fonts'
|
||||
import type { Locale } from '@/i18n/types'
|
||||
import { appConfig } from '@/config/env'
|
||||
import { formatDate, todayIso } from '@/lib/dates'
|
||||
import { getDict } from '@/i18n'
|
||||
|
||||
const MARGIN_X = 36
|
||||
const FOOTER_Y = 28
|
||||
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,
|
||||
@@ -14,19 +20,103 @@ export function drawFooter(
|
||||
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 left = appConfig.footerName
|
||||
const center = `${dict['pdf.export_date_prefix']}${formatDate(todayIso(), locale)}`
|
||||
const right = `${pageNumber} / ${totalPages}`
|
||||
const accent = rgb(0.28, 0.56, 0.42)
|
||||
|
||||
page.drawText(left, { x: MARGIN_X, y: FOOTER_Y, size: 9, font: fonts.bodyRegular, color: muted })
|
||||
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 centerW = fonts.bodyRegular.widthOfTextAtSize(center, 9)
|
||||
page.drawText(center, { x: (width - centerW) / 2, y: FOOTER_Y, size: 9, font: fonts.bodyRegular, color: muted })
|
||||
const logoW = 60
|
||||
const logoH = 23
|
||||
const topRowY = FOOTER_BASE_Y + LINE_HEIGHT + 2
|
||||
|
||||
const rightW = fonts.bodyRegular.widthOfTextAtSize(right, 9)
|
||||
page.drawText(right, { x: width - MARGIN_X - rightW, y: FOOTER_Y, size: 9, font: fonts.bodyRegular, color: muted })
|
||||
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,
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user