mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-08-05 15:42:14 +00:00
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
This commit is contained in:
committed by
GitHub
parent
05e8acc3b1
commit
773670c18f
@@ -11,9 +11,9 @@ use Psr\Http\Message\RequestInterface;
|
||||
|
||||
class GotenbergPdfDriver implements PdfDriver
|
||||
{
|
||||
public function loadView(string $template): ResponseStream
|
||||
public function loadView(string $template, array $metadata = []): ResponseStream
|
||||
{
|
||||
return new GotenbergPdfResponse(Gotenberg::send($this->buildRequest($template)));
|
||||
return new GotenbergPdfResponse(Gotenberg::send($this->buildRequest($template, $metadata)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -23,7 +23,7 @@ class GotenbergPdfDriver implements PdfDriver
|
||||
* below this line used to be inlined into loadView(), which meant the only
|
||||
* way to check that an option was set was to run a Gotenberg service.
|
||||
*/
|
||||
public function buildRequest(string $template): RequestInterface
|
||||
public function buildRequest(string $template, array $metadata = []): RequestInterface
|
||||
{
|
||||
$page = PdfPageSetup::fromConfig();
|
||||
[$width, $height] = $page->gotenbergPaper();
|
||||
@@ -66,6 +66,19 @@ class GotenbergPdfDriver implements PdfDriver
|
||||
$chromium->landscape();
|
||||
}
|
||||
|
||||
// Archival conformance, converted by LibreOffice inside the Gotenberg
|
||||
// image. PDF/A-3 is what the EU e-invoicing formats ask for. The value is
|
||||
// passed through unvalidated by the SDK, so an unsupported one surfaces
|
||||
// as an HTTP error from the service; the setting is a fixed list for
|
||||
// that reason.
|
||||
if ($pdfa = config('pdf.connections.gotenberg.pdfa')) {
|
||||
$chromium->pdfa($pdfa);
|
||||
}
|
||||
|
||||
if ($metadata !== []) {
|
||||
$chromium->metadata($metadata);
|
||||
}
|
||||
|
||||
// Must be attached before html(), which is terminal: it returns the built
|
||||
// request rather than the builder.
|
||||
if ($header = $this->companion($template, '_header')) {
|
||||
|
||||
Reference in New Issue
Block a user