A PHP library for low level access of PDF files

SetaPDF-Core

Access PDF documents at their lowest level with PHP

Merge ZUGFeRD XML with a PDF/A Document

ZUGFeRD

With SetaPDF-Core (since version 2.46) you can embed the XML package for a ZUGFeRD invoice (>=2.3) into an existing PDF/A document. The simple helper method also automatically recognizes the used profile and extends the PDF metadata accordingly.

This method modifies the original PDF/A document and keeps the complete internal structure.

The demo files we use in this demo are extracted and prepared from the official ZUGFeRD Information Package.

PHP
<?php

require_once('library/SetaPDF/Autoload.php');
// or if you use composer require_once('vendor/autoload.php');

$writer = new \SetaPDF_Core_Writer_Http('ZUGFeRD.pdf', true);
$document = \SetaPDF_Core_Document::loadByFilename('/path/to/pdfa.pdf', $writer);

// let's ensure the XML package
$zugferdXml = file_get_contents('/path/to/factur-x.xml');
// ...embed it and update all related information (such as XMP metadata)
\SetaPDF_Core_Zugferd::build($document, $zugferdXml);

$document->save()->finish();