Skip to content

Read incoming e-invoices with PHP

Since 2025 your suppliers in Germany may send you e-invoices. Here is how to read ZUGFeRD PDFs and XRechnung files in PHP, validate them and take the values into your accounting.

How-to13 Nov 2026 · about 8 minutes

In short

With quittio/core, read() reads the content of an XML or PDF file and readFile() a local file. Both recognise CII, UBL and ZUGFeRD/Factur-X PDFs, extract the embedded XML from the PDF and return the values in the same data model you use to create invoices. validateFile() checks the file on all enabled validation levels. Amounts are never corrected silently: Quittio reports differences as QUITTIO-DECLARED-TOTALS.

What an e-invoice contains

An e-invoice is an XML file according to EN 16931, in CII or UBL syntax. With XRechnung you usually get the XML only. With ZUGFeRD (Factur-X in France) you get a PDF/A-3 with the XML embedded as a file. The XML is what counts, not what the PDF shows. More on the formats in the guide ZUGFeRD, XRechnung or Peppol.

FileRecognised byContent
CII XMLroot element CrossIndustryInvoiceZUGFeRD 2.x / Factur-X MINIMUM to EXTENDED, XRechnung CII
UBL XMLroot element Invoice or CreditNote (UBL 2.1)EN 16931, XRechnung UBL, Peppol BIS Billing 3.0
PDFcontent starts with %PDFZUGFeRD 2.x / Factur-X, XRechnung in a PDF

Quittio detects the profile from the specification identifier (BT-24). XRechnung counts once the German country pack is registered.

Installation

Without Laravel, the core and the German country pack are enough. In Laravel, install quittio/quittio, which includes the integration.

composer require quittio/core quittio/country-de

Reading a file

read() always takes the content of the document, never a file name, so you can pass uploads and request bodies directly. readFile() reads a local file:

IncomingInvoiceController.php
use Quittio\Laravel\Facades\Quittio;

$read = Quittio::read($request->file('invoice')->get());   // content of an uploaded XML or PDF
$read = Quittio::readFile('/path/to/invoice.pdf');          // or a local file

$invoice = $read->data;          // InvoiceData as stated in the document
$invoice->number;                // "RE-2026-0042"
$invoice->seller->name;          // the supplier
$invoice->totals?->amountDue;    // amount due as stated in the document

$read->profile;                  // detected profile, e.g. "en16931" or "xrechnung"
$read->findings;                 // problems found while reading, e.g. QUITTIO-DECLARED-TOTALS
$read->embeddedFilename;         // for PDFs: factur-x.xml, xrechnung.xml …
incoming.php
use Quittio\Core\Quittio;
use Quittio\Country\DE\CountryDE;

$quittio = Quittio::create([], [new CountryDE]);

$read = $quittio->read(file_get_contents($_FILES['invoice']['tmp_name']));   // content of an uploaded XML or PDF
$read = $quittio->readFile('/path/to/invoice.pdf');                          // or a local file

$invoice = $read->data;          // InvoiceData as stated in the document
$invoice->number;                // "RE-2026-0042"
$invoice->seller->name;          // the supplier
$invoice->totals?->amountDue;    // amount due as stated in the document

$read->profile;                  // detected profile, e.g. "en16931" or "xrechnung"
$read->findings;                 // problems found while reading, e.g. QUITTIO-DECLARED-TOTALS
$read->embeddedFilename;         // for PDFs: factur-x.xml, xrechnung.xml …

The result is a ReadResult. data holds the values as stated in the document, syntax is cii or ubl, declaredTotals the stated totals and xml the XML that was read, for a PDF the embedded one.

Validate before booking

Reading does not validate the whole document. Before you book an invoice, check it on the same levels Quittio uses for its own invoices (EN 16931, XRechnung, Peppol, XSD; plus the KoSIT validator and veraPDF if you enabled them):

IncomingInvoiceController.php
$report = Quittio::validateFile($content);   // content of an XML or PDF
$report = Quittio::validatePath($path);      // or a local file

if (! $report->isValid()) {
    // reject the invoice, e.g. show $report->errors()
}
incoming.php
$report = $quittio->validateFile($content);   // content of an XML or PDF
$report = $quittio->validatePath($path);      // or a local file

if (! $report->isValid()) {
    // reject the invoice, e.g. show $report->errors()
}

How to set up the official validators is explained in the guide Validating e-invoices.

Taking the values into accounting

A complete example: accept an upload, validate it, extract the values for accounting.

IncomingInvoiceController.php
use Quittio\Laravel\Facades\Quittio;

$content = $request->file('invoice')->get();          // uploaded PDF or XML

$report = Quittio::validateFile($content);
if (! $report->isValid()) {
    return back()->withErrors(array_map(fn ($m) => "[{$m->code}] {$m->message}", $report->errors()));
}

$read = Quittio::read($content);
$invoice = $read->data;

$booking = [
    'supplier' => $invoice->seller->name,
    'supplier_vat_id' => $invoice->seller->vatId,
    'number' => $invoice->number,
    'issue_date' => $invoice->issueDate->toIsoString(),
    'due_date' => $invoice->dueDate?->toIsoString(),
    'amount_due' => (string) $invoice->totals?->amountDue->getAmount(),
    'currency' => $invoice->currency,
    'iban' => $invoice->paymentInstructions?->primaryCreditTransfer()?->accountId,
    'profile' => $read->profile,                           // e.g. "en16931" or "xrechnung"
];
incoming.php
$content = file_get_contents($_FILES['invoice']['tmp_name']);   // uploaded PDF or XML

$report = $quittio->validateFile($content);
if (! $report->isValid()) {
    return array_map(fn ($m) => "[{$m->code}] {$m->message}", $report->errors());   // e.g. to show them with the form
}

$read = $quittio->read($content);
$invoice = $read->data;

$booking = [
    'supplier' => $invoice->seller->name,
    'supplier_vat_id' => $invoice->seller->vatId,
    'number' => $invoice->number,
    'issue_date' => $invoice->issueDate->toIsoString(),
    'due_date' => $invoice->dueDate?->toIsoString(),
    'amount_due' => (string) $invoice->totals?->amountDue->getAmount(),
    'currency' => $invoice->currency,
    'iban' => $invoice->paymentInstructions?->primaryCreditTransfer()?->accountId,
    'profile' => $read->profile,                           // e.g. "en16931" or "xrechnung"
];

For a ZUGFeRD invoice of 24 hours at €95 net, $booking is:

booking.json
{"supplier":"Muster GmbH","supplier_vat_id":"DE123456789","number":"RE-2026-0042","issue_date":"2026-10-01","due_date":"2026-10-15","amount_due":"2713.20","currency":"EUR","iban":"DE02120300000000202051","profile":"en16931"}

Totals are never corrected silently

Quittio keeps the amounts as stated in the document and recalculates a copy from the lines for comparison. Every difference in the line amounts, the sum of lines, the totals without and with VAT, the VAT total and the amount due is reported as warning QUITTIO-DECLARED-TOTALS, for example:

Finding
QUITTIO-DECLARED-TOTALS: Amount due (BT-115): declared 2700.00, recalculated 2713.20.

$read->data->totals still holds the stated amount. Whether you reject such an invoice or ask the supplier is up to you.

Findings while reading

The reader is tolerant: it reads as much as possible and reports problems as findings instead of failing. Some examples:

CodeMeaning
BR-03The issue date (BT-2) is missing or unreadable
BR-05The invoice currency (BT-5) is missing or not an ISO 4217 code
QUITTIO-READER-UNKNOWN-PROFILEThe specification identifier (BT-24) is not known to this installation
QUITTIO-READER-PDF-CANDIDATESThe PDF embeds several invoice files with different content
QUITTIO-DECLARED-TOTALSThe stated amounts differ from the recalculation

The full list is in the documentation under Reading incoming invoices.

Limits and security

Incoming files come from outside, so Quittio limits what it accepts:

  • XML with a DOCTYPE is rejected, so there are no external entities (XXE) and no entity expansion.
  • Size limits: XML 10 MB, PDF 25 MB, every decompressed PDF stream 50 MB (configurable).
  • Encrypted PDFs cannot be read.
  • File names of embedded files are never used as paths.

An exception is thrown only when the document cannot be read at all: an unknown format, ZUGFeRD 1.0 (not EN 16931), a PDF without an embedded invoice, a missing or too large file. All three exception classes implement QuittioException.

On the command line (Laravel)

In Laravel, two Artisan commands show the content of a file and its validation report:

Terminal
php artisan quittio:read invoice.pdf          # number, date, profile, parties, lines, totals, findings
php artisan quittio:read invoice.xml --json   # InvoiceData as JSON
php artisan quittio:validate invoice.pdf      # validation report

Without Laravel there are no console commands; read() and validateFile() return the same data.

Frequently asked questions

Can I read ZUGFeRD invoices without Laravel?

Yes. read(), readFile() and validateFile() are part of quittio/core and run in any project with PHP 8.3. The page E-invoices with PHP gives an overview.

Do I have to extract the XML from the PDF myself?

No. Quittio finds the embedded XML of a ZUGFeRD or Factur-X PDF and reads it. embeddedFilename shows its file name.

Does Quittio correct wrong totals?

No. The values stay as stated in the document. Quittio reports differences from the recalculation as warning QUITTIO-DECLARED-TOTALS.

Does Quittio read ZUGFeRD 1.0?

No. ZUGFeRD 1.0 does not conform to EN 16931 and is rejected with a clear message.

Can I safely read uploads from unknown senders?

Quittio rejects XML with a DOCTYPE, limits sizes and PDF structures and never uses embedded file names as paths. Still validate the invoice before you book it.

Read incoming invoices in one line.

All fields, findings and limits are in the documentation.