I use mPDF library to generate PDF/A-3 file, everything work fine except

  1. my pdf file output from this library indicate file to only conform with PDF/A-1B.
  2. 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.

enter image description here

enter image description here

$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

1

There are 1 best solutions below

0
K J On

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.

enter image description here

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

  • correctly duplicated MetaData in XMP format (/Metadata/Length 4072/Subtype/XML + /Metadata/Length 865/Subtype/XML)
  • correctly duplicated colour values in a colour profile (/Length 3024)
  • correctly duplicated contents in both bloated PDF and bloated XML format (/EmbeddedFile/Subtype/text#2Fxml/Length 11528)

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

Example Command Line Note the ‘\’ indicates a line break purely to fit the command line on this page, you should not include these!

gs --permit-file-read=/usr/home/me/zugferd/ -sDEVICE=pdfwrite -dPDFA=3\
-sColorConversionStrategy=RGB -sZUGFeRDXMLFile=/usr/home/me/zugferd/invoice.xml\
-sZUGFeRDProfile=/usr/home/me/rgb.icc -sZUGFeRDVersion=2p1 -sZUGFeRDConformanceLevel=BASIC\
-o /usr/home/me/zugferd/zugferd.pdf\
/usr/home/me/zugferd/zugferd.ps /usr/home/me/zugferd/original.pdf  

Clearly the paths here are for illustration only and need to be customised.