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.

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 required metadata and document structure.

Level Description
MINIMUM Includes the minimum required metadata that identifies the invoice.
BASIC Does not include additional metadata or document structure.
BASIC_WL Includes additional metadata that improves invoice readability.
COMFORT Includes additional metadata and document structure that improve readability and usability.
EXTENDED Includes additional metadata and document structure that improve readability, usability, and interoperability.
EN_16931 Complies with the EN 16931 electronic invoicing standard.
X_RECHNUNG Complies with the XRechnung electronic invoicing standard in Germany.

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);
            }
        }
    }
}