How to extract the XML from a ZUGFeRD or Factur-X PDF

A ZUGFeRD or Factur-X invoice looks like any other PDF. What makes it an e-invoice is a file attached inside it: an XML file with the same invoice as structured data. The PDF is the page people read; the XML is what accounting software reads. Most PDF viewers show you the page and never mention the attachment.

This page shows how to get at that XML on a Mac. It’s part of our guide to e-invoices on a Mac.

What’s inside, measured

We checked the 78 PDFs in the “correct” ZUGFeRD 2 folder of the open ZUGFeRD corpus, a public collection of sample invoices, on November 7, 2026:

What we found Files
Had an XML attachment 78 of 78
XML in CII syntax (CrossIndustryInvoice) 78 of 78
ZUGFeRD 2.0, attachment named zugferd-invoice.xml 29
ZUGFeRD 2.1 and later, named factur-x.xml 38
Factur-X, named factur-x.xml 8
No version in the file name (2 factur-x.xml, 1 zugferd-invoice.xml) 3
Carried other attachments as well as the XML 6

So the name depends on the version, and you can’t assume it. The safe rule is the one every method below uses: take the attachment whose name ends in .xml. That matters for the six files with extras. The sample electrician’s invoice from Elektron, for example, also carries a photo (Aufmass.png) and a work report (ElektronRapport.pdf) next to zugferd-invoice.xml.

Method 1: let Unfela read it, no extraction

If what you want is the data, not the file, you don’t need to extract anything. Drag the PDF into Unfela and it reads the XML inside, then shows the fields with their state: number, dates, seller, VAT ID, amounts and IBAN. For the Elektron sample that’s invoice 181301674 from ELEKTRON Industrieservice GmbH, 252.10 net, 47.90 VAT, 300.00 total.

Because the values come from the data, not from reading the page, they don’t depend on the layout. Unfela still checks them: a total that doesn’t match the other amounts goes to Needs Review, not Verified. From there you can export the list to CSV, or to Excel with Mac Pro. Converting e-invoices to Excel or CSV shows what the columns look like.

Method 2: Adobe Acrobat’s Attachments panel

Preview doesn’t show PDF attachments, but Adobe Acrobat does. According to Adobe’s help page, on a Mac:

  1. Open the PDF in Acrobat.
  2. Choose View → Show/Hide → Side panels → Attachments.
  3. In the list, find the file ending in .xml, right-click it and choose Open Attachment.

This is fine for one invoice. For a folder of them, use Terminal.

Method 3: qpdf in Terminal

qpdf is a free, open-source command-line tool for PDFs. Install it with Homebrew:

brew install qpdf

See what’s attached:

qpdf --list-attachments invoice.pdf

For the Elektron sample, that prints:

Aufmass.png -> 31,0
ElektronRapport.pdf -> 30,0
zugferd-invoice.xml -> 29,0

Save the XML next to the PDF:

qpdf --show-attachment=zugferd-invoice.xml invoice.pdf > invoice.xml

A whole folder at once

Run this in the folder with your PDFs. It finds the XML in each one, whatever it’s called, and saves it under the PDF’s name:

for f in *.pdf; do
  n=$(qpdf --list-attachments "$f" | grep -oE "^[^ ]+\.xml" | head -1)
  if [ -n "$n" ]; then qpdf --show-attachment="$n" "$f" > "${f%.pdf}.xml"; echo "$f -> ${f%.pdf}.xml"; else echo "$f: no XML inside"; fi
done

We ran it on November 7, 2026, with qpdf 12.4.2 in the Mac’s default shell, zsh, including a file name with a space and an ordinary PDF with no attachment, which it reported as “no XML inside”. Across the 78 corpus samples, qpdf extracted every XML. One file had a slightly broken internal index; qpdf printed a warning, repaired it on the fly and still extracted the XML.

Method 4: Python

If you already use Python, pypdf reads attachments too. This saves every XML attachment next to the PDF; we tested it with pypdf 7.0.0 on all 78 samples:

import sys
from pypdf import PdfReader

for name, contents in PdfReader(sys.argv[1]).attachments.items():
    if name.lower().endswith(".xml"):
        open(name, "wb").write(contents[0])
        print("saved", name)

Run it as python3 extract_xml.py invoice.pdf, after installing pypdf with python3 -m pip install pypdf.

What to do with the XML

  • Read it. An XML file opens as raw tags in a browser or text editor. To see it as an invoice, open it in an e-invoice app; it’s the same situation as opening an XRechnung on a Mac.
  • Put it in a spreadsheet. Convert it to CSV or Excel with Unfela or a free script.
  • Keep the PDF. The extracted XML is a copy. The PDF you received, with its attachment, is the invoice.

If there’s no XML

If a PDF has no .xml attachment, it isn’t a ZUGFeRD or Factur-X invoice. It’s an ordinary PDF that only looks like one, and the data has to be read from the page. Unfela does that too, and marks each value it reads from the page as Verified only when it sits next to a fitting label and passes its checks. Here’s how that works.

Questions

How do I know if a PDF is a ZUGFeRD invoice at all?

Check whether it has an XML attachment. In Terminal, qpdf --list-attachments invoice.pdf lists every embedded file. If it prints "has no embedded files", or no file ending in .xml, it's an ordinary PDF.

What is the XML file called?

In the 78 valid ZUGFeRD 2 and Factur-X samples we checked, ZUGFeRD 2.0 files used zugferd-invoice.xml and ZUGFeRD 2.1 and later and Factur-X files used factur-x.xml. Take whichever file ends in .xml.

Does extracting the XML change the PDF?

No. All the methods here copy the attachment out and leave the PDF as it was.

Can I open the extracted XML in Excel?

You'll get nested tags rather than a table. Use a converter that picks the fields you need; our guide to converting XRechnung or ZUGFeRD to Excel or CSV has a free script.