I use mPDF library to generate PDF/A-3 file, everything work fine except
- my pdf file output from this library indicate file to only conform with PDF/A-1B.
- my XML attachment in pdf document's output indicate to be 0.00Bytes although I can open attached file and see detail.
How to fix this issue? Here is some of my code.
$defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
$mpdf = new \Mpdf\Mpdf([
'format' => [210, 297]
, 'mirrorMargins' => 1
, 'mode' => 'utf-8'
, 'PDFA' => true
, 'PDFAauto' => false
, 'PDFAversion'=> 'A-3'
, 'fontDir' => array_merge($fontDirs, [
$_SERVER['DOCUMENT_ROOT'] . '/font',
])
, 'fontdata' => $fontData + [ // lowercase letters only in font key
'sarabun' => [
'R' => 'THSarabunNew.ttf'
, 'B' => 'THSarabunNew Bold.ttf'
]
]
, 'default_font' => 'sarabun'
, 'debug' => true
]);
$mpdf->SetAssociatedFiles([[
'name' => $invoiceNumber . '.xml'
, 'mime' => 'text/xml'
, 'description' => 'Tax Invoice XML Data'
, 'AFRelationship' => 'Alternative'
, 'content' => $xml
]]);
$mpdf->SetAdditionalXmpRdf($rdf);
$mpdf->SetTitle($invoiceNumber);
$mpdf->SetAuthor($masterCompany['companyName']);
$mpdf->SetCreator($masterCompany['companyName']);
$mpdf->SetSubject('Receipt/Tax Invoice');
$mpdf->SetKeywords('Tax Invoice');
$mpdf->WriteHTML($html);
$mpdf->Output($invoiceNumber . '.pdf', 'I');
I can't find much examples in detail how to output PDF/A-3 document from mPDF on the internet. Here is what I got from there website https://mpdf.github.io/what-else-can-i-do/pdf-a3-xmp-rdf.html
0 bytes reported size is perfectly normal for this XML format when attached, as it is not a PDF. Size on disk = 12.0 KB (12,288 bytes). Comparative size if sent in zip content about 2 KB, even bloated within say a docX.
Here is one of the samples from within the 2.2 German specification.
The draconian requirements of PDF/A-3b are totally unnecessary for such a simple application archival method, however it is what it is, designed by a committee !
To pass International PDF/A-3b ZUGFeRD level a PDF needs
All wrapped up in a complex PDF/A format. For that source 2 KB invoice, the total still encoded in memory workspace is likely to consume about 238 KB (243,833 bytes).
The generic way to build such a beast is use GhostScript as a means to upgrade and leverage the components correctly into PDF/A-3b structure with EXACTLY the correct colour profile.
For details read https://ghostscript.com/blog/zugferd.html
Programming detail heavily depends on your choice of printers colours!
Roughly
Clearly the paths here are for illustration only and need to be customised.