Creating ZUGFeRD Invoices with PDFEdit
Requirements: Secure PDF or PDF SDK
Introduction
ZUGFeRD is a standardized electronic invoicing format developed to simplify the exchange of invoices between businesses and public administrations. It combines a human-readable PDF/A-3 invoice with a machine-readable XML file embedded within the PDF, enabling seamless automation, validation, and archiving of invoice data. This hybrid approach ensures compliance with EU standards while maintaining visual compatibility with traditional invoice processing.
Using the PDFEdit component from Secure PDF or PDF SDK, this integration of XML data into a PDF to create a ZUGFeRD-compliant invoice can be achieved efficiently and programmatically.
ZUGFeRD and Factur-X
ZUGFeRD and Factur-X are both hybrid invoice formats that combine a human-readable PDF with embedded machine-readable XML data. Although ZUGFeRD originated in Germany and Factur-X in France, both formats have been harmonized and now share a common technical foundation. Starting with ZUGFeRD version 2.1, the standard is fully aligned with Factur-X, meaning any invoice conforming to ZUGFeRD 2.1 or later is also Factur-X compliant. The PDFEdit component does not enforce a specific ZUGFeRD version when generating invoices – it can produce valid ZUGFeRD invoices based on the input PDF and XML data.
ZUGFeRD Format Requirements
The following pieces are required for ZUGFeRD invoices:
-
PDF/A-3 Format
The PDF, serving as the human-readable part of the hybrid invoice and container for the XML, must conform to PDF/A-3 (a, b, or u). Additional attachments (e.g., images or spreadsheets) are allowed. -
Single XML Attachment
Only one XML invoice is allowed, associated at document level using the AFRelationship key in the file specification dictionary. In the latest versions of ZUGFeRD the filename of the attachment must be factur-x.xml (or xrechnung.xml for the XRechnung profile). This XML document is the machine-readable part of the hybrid invoice. -
XMP Metadata
The PDF must include XMP metadata containing key invoice details as well as PDF/A information, which is covered in more detail in the next section.
XMP Metadata
To comply with the ZUGFeRD specification, a PDF invoice must include XMP metadata, a standardized form of embedded metadata that describes the attached XML invoice and the PDF/A-3 conformance. This metadata does not contain the invoice data itself, but provides descriptive information about the embedded XML file, such as the document type, filename, schema version, and profile (e.g., BASIC, COMFORT, EN 16931).
PDFEdit automatically constructs the XMP metadata by extracting the necessary values from the attached XML invoice before embedding the result into the PDF.
Generating a ZUGFeRD Invoice
The code below demonstrates how to create a fully compliant ZUGFeRD invoice using the PDFEdit component. First, it attaches the XML invoice as an embedded file using the AddAttachment method. When patElectronicInvoice is passed to the AttachmentType parameter, the component automatically:
- Configures the appropriate AFRelationship to define the relationship between the XML and the PDF content,
- Generates the XMP metadata from the invoice data, and
- Embeds it into the PDF.
The result is then saved as a valid PDF/A-3 file that combines both the human-readable PDF and machine-readable XML, fulfilling the core requirement of the ZUGFeRD and Factur-X specifications.
PDFEdit pdfedit = new PDFEdit();
pdfedit.InputFile = "pdfa3b.pdf";
pdfedit.OutputFile = "ZUGFeRD_invoice.pdf";
pdfedit.Overwrite = true;
pdfedit.Open();
pdfedit.AddAttachment("factur-x.xml", "", (int)PDFAttachmentTypes.patElectronicInvoice);
pdfedit.Close();
Once the XML invoice has been attached and the XMP metadata embedded, the resulting PDF can be validated for ZUGFeRD compliance using external tools if desired. Validation support is also planned for a future version of the component.
Conclusion
Creating ZUGFeRD invoices is a common requirement for many companies and is becoming increasingly popular as electronic invoicing standards continue to evolve across Europe. Using the PDFEdit component, this process can be fully automated, ensuring your invoices are both human-readable and machine-processable. By following this article, you can generate valid ZUGFeRD or Factur-X invoices that meet modern e-invoicing standards and are ready for exchange and archiving.
We appreciate your feedback. If you have any questions, comments, or suggestions about this article please contact our support team at support@nsoftware.com.