mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-08-04 23:22:12 +00:00
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
34 lines
948 B
PHP
34 lines
948 B
PHP
<?php
|
|
|
|
namespace App\Support\Pdf;
|
|
|
|
use App\Models\Company;
|
|
|
|
/**
|
|
* Document properties written into the PDF itself.
|
|
*
|
|
* Generated files used to carry none, so an archive of them showed a column of
|
|
* blank titles and no author. It also matters for PDF/A, whose whole point is
|
|
* being readable years later by someone who has only the file.
|
|
*
|
|
* Both drivers take the same key names: dompdf via addInfo(), Gotenberg via
|
|
* metadata().
|
|
*/
|
|
final class PdfMetadata
|
|
{
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
public static function forDocument(string $subject, ?string $number, ?Company $company): array
|
|
{
|
|
$title = trim($subject.' '.($number ?? ''));
|
|
|
|
return array_filter([
|
|
'Title' => $title,
|
|
'Subject' => $subject,
|
|
'Author' => $company?->name,
|
|
'Creator' => config('app.name', 'InvoiceShelf'),
|
|
], fn ($value) => is_string($value) && $value !== '');
|
|
}
|
|
}
|