Skip to main content

Generate ZUGFeRD-Compliant PDF Invoices

  • 3 minutes to read

ZUGFeRD (Zentraler User Guide des Forums elektronische Rechnung Deutschland) is a standard for electronic invoices in Germany. A ZUGFeRD invoice combines a PDF/A-3 document with an embedded XML file that contains structured invoice data.

The PDF Document API allows you to generate ZUGFeRD-compliant PDF invoices. Call the PdfDocument.attachZugferdInvoice() method to attach ZUGFeRD invoice XML data to a PDF document.

The API supports several overloads that accept different XML data sources. The attachZugferdInvoice() method accepts invoice XML data as a byte array, an InputStream, or a ReadableByteChannel. Overloads also allow you to specify the ZUGFeRD version and conformance level. If you omit the version and conformance level, the API uses ZUGFeRD 1.0 (VERSION_1_0) and the BASIC conformance level.

Note

If the document already contains a ZUGFeRD invoice attachment with the same file name, the API replaces the existing attachment and updates the associated XMP metadata automatically.

PDF/A-3 Prerequisite

ZUGFeRD requires a PDF/A-3 document that embeds the invoice XML file as an associated attachment. The PDF document must satisfy the PDF/A-3 specification before it can serve as a compliant electronic invoice. For example, the document must include embedded fonts, document metadata, an output intent (ICC color profile), and only PDF/A-3-compatible content. Attaching the XML invoice alone does not convert a PDF document to PDF/A-3. To convert the document, call the PdfDocument.convertToPdfA(compatibility) method with the PdfACompatibility.PDF_A3B value.

Refer to the following help topic for additional information: Convert and Validate PDF/A and PDF/UA Documents — PDF Document API for Java.

Supported ZUGFeRD Versions

Version Description
VERSION_1_0 ZUGFeRD 1.0 format
VERSION_2_0_1 ZUGFeRD 2.0.1 and later
VERSION_2_1 ZUGFeRD 2.1 through 2.3
VERSION_2_3_2 ZUGFeRD 2.3.2 through 2.5

Supported ZUGFeRD Conformance Levels

The PDF Document API supports the following ZUGFeRD conformance levels for PDF/A-3 documents. All conformance levels embed invoice XML data in a PDF/A-3 document. The selected level determines the invoice information that the XML data contains.

Level Description
MINIMUM Minimum level (minimum invoice information required on CHORUS PRO, equivalent to a classic header OCR and manual validation data capture).
BASIC Basic level (the invoice contains basic details and additional information included as free text).
BASIC_WL Basic WL level (invoice information that is typically required or useful for process automation).
COMFORT Comfort level (the details are structured and fully automated).
EXTENDED Extended EN 16931 level.
EN_16931 Complies with the EN 16931 electronic invoicing standard.
X_RECHNUNG Complies with the XRechnung electronic invoicing standard in Germany.

If you pass the ZugferdConformanceLevel.NONE value, the attachZugferdInvoice method does not attach the invoice.

Attach a ZUGFeRD Invoice to a PDF Document

The following code snippet attaches a ZUGFeRD invoice XML file to an existing PDF document:

import com.devexpress.docs.pdf.*;

import java.io.*;
import java.nio.file.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try (InputStream stream = Files.newInputStream( Path.of("Invoice.pdf"));
             PdfDocument pdfDocument = new PdfDocument(stream)) {

            // Load the invoice XML data.
            byte[] invoiceData = Files.readAllBytes(Path.of("ZUGFeRD-invoice.xml"));

            // Attach the XML invoice and specify the ZUGFeRD version and conformance level.
            pdfDocument.attachZugferdInvoice(
                    invoiceData,
                    ZugferdVersion.VERSION_2_3_2,
                    ZugferdConformanceLevel.BASIC);

            // Save the PDF document with the embedded ZUGFeRD invoice.
            try (OutputStream outputStream =
                         Files.newOutputStream( Path.of("Invoice_ZUGFeRD.pdf"))){
                pdfDocument.save(outputStream);
            }
        }
    }
}