feat(pdf): drawHeader with practitioner + animal/owner/date
This commit is contained in:
1 parent
ba30e0dbaf
commit
099ebf326b
1 file changed
+58
-10
+58
-10
@@ -1,14 +1,62 @@
|
||||
import type { PDFPage } from 'pdf-lib'
|
||||
import { rgb, type PDFPage } from 'pdf-lib'
|
||||
import type { EmbeddedFonts } from '@/pdf/fonts'
|
||||
import type { Report } from '@/domain/schema/report'
|
||||
import { formatDateFr } from '@/lib/dates'
|
||||
|
||||
/**
|
||||
* Draws the page header: practitioner block (left) + animal/owner/date (right).
|
||||
*/
|
||||
export function drawHeader(
|
||||
_page: PDFPage,
|
||||
_report: Report,
|
||||
_fonts: EmbeddedFonts,
|
||||
): void {
|
||||
throw new Error('not implemented')
|
||||
const MARGIN_X = 36
|
||||
const TOP_Y = 800
|
||||
|
||||
export function drawHeader(page: PDFPage, report: Report, fonts: EmbeddedFonts): void {
|
||||
const { width } = page.getSize()
|
||||
const ink = rgb(0.12, 0.11, 0.09)
|
||||
const muted = rgb(0.42, 0.39, 0.35)
|
||||
|
||||
const left = [
|
||||
report.practitioner.name,
|
||||
report.practitioner.cabinet,
|
||||
report.practitioner.contact,
|
||||
report.practitioner.siret ? `SIRET ${report.practitioner.siret}` : undefined,
|
||||
].filter(Boolean) as string[]
|
||||
|
||||
const y = TOP_Y
|
||||
left.forEach((line, i) => {
|
||||
page.drawText(line, {
|
||||
x: MARGIN_X,
|
||||
y: y - i * 12,
|
||||
size: i === 0 ? 11 : 9,
|
||||
font: i === 0 ? fonts.bodyBold : fonts.bodyRegular,
|
||||
color: i === 0 ? ink : muted,
|
||||
})
|
||||
})
|
||||
|
||||
const animalLine = [
|
||||
report.animal.name,
|
||||
report.animal.breed ? `(${report.animal.breed})` : '',
|
||||
report.animal.age ? `· ${report.animal.age}` : '',
|
||||
].filter(Boolean).join(' ')
|
||||
|
||||
const right = [
|
||||
animalLine,
|
||||
`Propriétaire : ${report.owner.name}`,
|
||||
formatDateFr(report.date),
|
||||
]
|
||||
right.forEach((line, i) => {
|
||||
const size = i === 0 ? 11 : 9
|
||||
const font = i === 0 ? fonts.bodyBold : fonts.bodyRegular
|
||||
const w = font.widthOfTextAtSize(line, size)
|
||||
page.drawText(line, {
|
||||
x: width - MARGIN_X - w,
|
||||
y: y - i * 12,
|
||||
size,
|
||||
font,
|
||||
color: i === 0 ? ink : muted,
|
||||
})
|
||||
})
|
||||
|
||||
page.drawLine({
|
||||
start: { x: MARGIN_X, y: y - 40 },
|
||||
end: { x: width - MARGIN_X, y: y - 40 },
|
||||
thickness: 0.5,
|
||||
color: muted,
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user