mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-08-04 15:12: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
80 lines
2.6 KiB
PHP
80 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Rules\CssLength;
|
|
use App\Rules\PublicHttpUrl;
|
|
use App\Support\Pdf\GotenbergHostPolicy;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class PDFConfigurationRequest extends FormRequest
|
|
{
|
|
/** Formats the Gotenberg image can actually produce, verified against gotenberg:8. */
|
|
public const PDFA_FORMATS = ['PDF/A-1b', 'PDF/A-2b', 'PDF/A-3b'];
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return array_merge($this->pageRules(), $this->driverRules());
|
|
}
|
|
|
|
/**
|
|
* Page geometry is driver-neutral, so it is validated the same way whichever
|
|
* driver is selected. Paper size used to live under `gotenberg_papersize` as
|
|
* a single "210mm 297mm" string, which dompdf had no equivalent of and could
|
|
* not consume.
|
|
*/
|
|
private function pageRules(): array
|
|
{
|
|
$length = ['nullable', 'string', new CssLength];
|
|
|
|
return [
|
|
'pdf_driver' => ['required', 'string'],
|
|
'pdf_paper_width' => ['required', 'string', new CssLength],
|
|
'pdf_paper_height' => ['required', 'string', new CssLength],
|
|
'pdf_orientation' => ['required', Rule::in(['portrait', 'landscape'])],
|
|
'pdf_margin_top' => $length,
|
|
'pdf_margin_right' => $length,
|
|
'pdf_margin_bottom' => $length,
|
|
'pdf_margin_left' => $length,
|
|
'pdf_page_numbers' => ['sometimes', 'boolean'],
|
|
];
|
|
}
|
|
|
|
private function driverRules(): array
|
|
{
|
|
if ($this->get('pdf_driver') !== 'gotenberg') {
|
|
return [];
|
|
}
|
|
|
|
// The operator-declared Gotenberg host skips the private-network
|
|
// check; anything else is still held to it. See GotenbergHostPolicy.
|
|
$isDeclaredHost = GotenbergHostPolicy::isExemptFromPrivateNetworkGuard(
|
|
$this->input('gotenberg_host')
|
|
);
|
|
|
|
return [
|
|
'gotenberg_host' => [
|
|
'required',
|
|
'url',
|
|
Rule::when(! $isDeclaredHost, [new PublicHttpUrl]),
|
|
],
|
|
// A fixed list rather than a free string: the SDK forwards whatever
|
|
// it is given, so an unsupported value would only fail later as an
|
|
// HTTP error from the Gotenberg service.
|
|
'gotenberg_pdfa' => ['nullable', Rule::in(self::PDFA_FORMATS)],
|
|
];
|
|
}
|
|
}
|