PHP code example of invoicexml / zugferd-xrechnung
1. Go to this page and download the library: Download invoicexml/zugferd-xrechnung library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$pdf = $client->createZugferd($invoice, [
'language' => 'de', // labels of the rendered PDF: en, de or fr
'brandColor' => '#0F766E',
'logoUrl' => 'https://example.com/logo.png',
]);
$pdf->save($pdf->filename); // for example invoice-zugferd-INV-2026-00045.pdf
$result = $client->validateZugferd('incoming.pdf'); // or validateXrechnung('incoming.xml')
if (!$result->valid) {
foreach ($result->errors as $error) {
echo "{$error->rule} ({$error->layer}): {$error->message}\n";
}
}
$report = $client->validateZugferdReport('incoming.pdf', validationLanguage: 'de'); // or validateXrechnungReport('incoming.xml')
$report->file->save('report.pdf');
if ($report->valid === false) {
echo "The invoice failed validation, see the report.\n";
}
$data = $client->extractJson('incoming.pdf'); // ZUGFeRD PDF or XRechnung XML
$invoice = $data['invoice']; // same shape the create methods accept
$zip = $client->extractAttachments('incoming.pdf'); // supporting documents as a ZIP
$parsed = $client->parseJson('scan.pdf');
$invoice = $parsed['invoice']; // same shape the create methods accept