Convert PDF to PDF-A ZUGFeRD in C# and .NET

ZUGFeRD is a German and European standard for hybrid electronic invoices, combining visual PDF and structured XML data. It uses the ISO 19005-3:2012 (PDF/A-3) standard to embed XML within PDF, enabling long-term storage and automated data processing.

Key aspects of ZUGFeRD and ISO:

  • PDF/A-3 (ISO 19005-3): ZUGFeRD is based on the ISO 19005-3 standard, which allows any file (in this case, XML) to be embedded within a PDF document. This enables automatic data extraction while maintaining a human-readable format.
  • Hybrid format: The PDF file contains both a human-readable invoice and machine-readable structured data (usually UN/CEFACT CII), enabling automatic processing in accounting systems.
  • Standard compliance: ZUGFeRD complies with the European standard EN 16931 for electronic invoicing.
  • ISO Country Codes: The ZUGFeRD structure uses a two-character country code in accordance with ISO 3166-1 (e.g., DE, AT, FR).

ZUGFeRD 2.0 and later versions are often referred to as Factur-X, emphasizing their international compatibility.

Step-by-step:

  1. Define a path variable pointing to the folder containing the input and output PDF files. And the path and description of another file named "ZUGFeRD.xml" that contains invoice metadata that complies with the ZUGFeRD standard.
  2. Create a document object by loading an existing PDF file (e.g., "ZUGFeRD_Result.pdf") from the path.
  3. Upload the PDF document you want to convert to PDF/A3 format.
  4. Adding metadata from the XML file.
  5. Save the result as a new PDF/A3 document based on Factur-X ISO.

Code Snippet:


            string inpFile = @"..\..\..\ZUGFeRD\ZUGFeRD.pdf";
            string outFile = @"..\..\..\ZUGFeRD\ZUGFeRD_Result.pdf";
            string xmlInfo = @"..\..\..\ZUGFeRD\ZUGFeRD.xml";

            using (var document = PdfDocument.Load(Path.GetFullPath(inpFile)))
            {
                // Create PDF save options.
                var pdfOptions = new PdfSaveOptions()
                {
                    Version = PdfVersion.PDF_A_3A,
                    FacturXXml = File.ReadAllText(xmlInfo)
                };
                document.Save(outFile, pdfOptions);
            }

Key Features:

  • Generate ZUGFeRD 2.2 compliant hybrid PDFs.
  • Embed XRechnung XML directly into PDF/A-3.
  • Support for all ZUGFeRD profiles (Basic, Comfort, Extended).
  • Automatic PDF/A-3 conversion and validation.
  • Preserve original PDF layout and design.
  • Digital signature support for authenticity.
  • Compatible with all German tax requirements.

PDF .Net by SautinSoft supports ZUGFeRD 2.2 (Factur-X), which is fully compatible with XRechnung and European standard EN 16931. This ensures maximum compatibility across German and European systems.

SautinSoft solutions allow to receive PDF/A-3 with embedded XML meeting all requirements and you will get mandatory compliance for German public sector invoicing, Automatic Leitweg-ID validation for government routing, Built-in validation for France tax regulations.

Standards support: The library supports Factur-X (ZUGFeRD 2.2), which complies with the European standard EN 16931.

PDF/A-1A, PDF/A-1B, PDF/A-2A, PDF/A-2B, PDF/A-2U, PDF/A-3A, PDF/A-3B, PDF/A-3U, PDF/A-4E.

Cross-platform: Works on Windows, Linux, and macOS (.NET 6/7/8/9/10, Net Framework 4.6 -4.8, Standard).

Complete code

using System;
using System.IO;
using System.Reflection;
using SautinSoft;
using SautinSoft.Pdf;
using SautinSoft.Pdf.Content;

namespace Sample
{
    class Sample
    {
        /// <summary>
        /// Convert PDF to PDF-A ZUGFeRD using C# and .NET.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/pdf/help/net/developer-guide/convert-pdf-to-pdfa-zugferd.php
        /// </remarks>
        static void Main(string[] args)
        {
            // Before starting this example, please get a free trial key:
            // https://sautinsoft.com/start-for-free/

            // Apply the key here:
            // PdfDocument.SetLicense("...");
            string inpFile = @"..\..\..\ZUGFeRD\ZUGFeRD.pdf";
            string outFile = @"..\..\..\ZUGFeRD\ZUGFeRD_Result.pdf";
            string xmlInfo = @"..\..\..\ZUGFeRD\ZUGFeRD.xml";
            // Load a PDF document.
            using (var document = PdfDocument.Load(Path.GetFullPath(inpFile)))
            {
                // Create PDF save options.
                var pdfOptions = new PdfSaveOptions()
                {
                //ZUGFeRD is a German and European standard for hybrid electronic invoices, combining visual PDF and structured XML data. 
				//It uses the ISO 19005-3:2012 (PDF/A-3) standard to embed XML within PDF, enabling long-term storage and automated data processing.
				// Select the desired PDF/A version.
                    Version = PdfVersion.PDF_A_3A,
                    FacturXXml = File.ReadAllText(xmlInfo)
                };

                // Save a PDF document like the FacturX Zugferd.
				// Read more information about Factur-X: https://fnfe-mpe.org/factur-x/

                document.Save(outFile, pdfOptions);
            }
        }
    }
}

Download