Files
InvoiceShelf/resources/scripts/api/services/pdf.service.ts
Darko Gjorgjijoski 773670c18f feat(pdf): archival PDF/A output and document properties (#732)
Generated files carried no document properties at all, so an archive of them
showed a column of blank titles and no author. Title, Subject, Author and
Creator are now written from the document number and company, on both drivers:
dompdf via addInfo(), Gotenberg via metadata().

dompdf needed more than the API call. It reads Title from the <title> element
during render(), which happens after addInfo(), so metadata set through the API
alone was silently overwritten by whatever the template put there and the two
drivers disagreed about what the file was called. The title is written into the
markup as well, escaped.

Also adds an archival format setting for Gotenberg: off, PDF/A-1b, -2b or -3b.
PDF/A-3 is what the EU e-invoicing formats expect. Verified against a stock
gotenberg:8 -- LibreOffice inside the image does the conversion and the output
carries the right pdfaid:part in its XMP -- so no extra components are needed.

A fixed list rather than free text, because the SDK forwards whatever it is
given and an unsupported value would surface only as an HTTP error from the
service at render time. Empty is a real choice meaning an ordinary PDF, so it
overrides an env default rather than falling through it.

Gotenberg only: dompdf cannot produce PDF/A.

Claude-Session: https://claude.ai/code/session_01QmECndmNZwzN65Zz9P87dF
2026-08-01 14:37:22 +02:00

60 lines
1.6 KiB
TypeScript

import { client } from '../client'
import { API } from '../endpoints'
export type PdfDriver = string
/**
* Page geometry, applied whichever driver renders. Sizes and margins are CSS
* lengths (e.g. "210mm"), the only notation both drivers accept without loss.
*/
export interface PdfPageSetup {
pdf_paper_width: string
pdf_paper_height: string
pdf_orientation: 'portrait' | 'landscape'
pdf_margin_top: string
pdf_margin_right: string
pdf_margin_bottom: string
pdf_margin_left: string
/**
* Gotenberg only: Chromium repeats a footer template and substitutes the page
* counts. Carried by both driver forms even though only one renders the
* control, so saving from dompdf cannot clear the choice.
*/
pdf_page_numbers: boolean
}
export interface DomPdfConfig extends PdfPageSetup {
pdf_driver: string
}
export interface GotenbergConfig extends PdfPageSetup {
pdf_driver: string
gotenberg_host: string
/** '' for an ordinary PDF, or one of the PDF/A conformance levels. */
gotenberg_pdfa: string
}
export type PdfConfig = DomPdfConfig | GotenbergConfig
export interface PdfConfigResponse {
pdf_driver: string
[key: string]: unknown
}
export const pdfService = {
async getDrivers(): Promise<PdfDriver[]> {
const { data } = await client.get(API.PDF_DRIVERS)
return data
},
async getConfig(): Promise<PdfConfigResponse> {
const { data } = await client.get(API.PDF_CONFIG)
return data
},
async saveConfig(payload: PdfConfig): Promise<{ success?: string; error?: string }> {
const { data } = await client.post(API.PDF_CONFIG, payload)
return data
},
}