The ZUGFeRD / Factur-X standard is a hybrid electronic invoice format that consists of two parts:

  • A PDF visual, human-readable representation of the invoice.
  • An XML file that contains invoice data in a structured form that can be processed automatically.

This article shows how to use the MailMerge TX Text Control .NET Server for ASP.NET
DocumentServer Namespace
MailMerge Class
The MailMerge class is a .NET component that can be used to effortlessly merge template documents with database content in .NET projects, such as ASP.NET web applications, web services or Windows services.
class to merge invoice data into a template and how to embed the generated ZUGFeRD XML to the final PDF document.

ZUGFeRD-csharp

In this sample, we utilize the GitHub project ZUGFeRD-csharp that is also available as a NuGet package.

ZUGFeRD-csharp GitHub repository

ZUGFeRD-csharp NuGet package

The Template

The following screenshot shows a very simple invoice template with fields according to the following Order data structure. You can see the merge fields for the Buyer and the merge block highlighted in red to repeat the LineItems.

Invoice template

The Data Source

The class Order contains all data required for an invoice generation process including address data for the buyer, the seller and the sold line items. Some properties such as LineTotalAmount and TaxTotalAmount are calculated automatically based on the added line items.

Loading...

Additionally, the class Order contains a property that generates the required ZUGFeRD XML. The property get method is basically matching the data source to the required properties of the InvoiceDescriptor that generates the XML.

Loading...

Creating the Invoice

The static method Create of the Invoice class is doing the actual merging work and embeds the generated XML into the created PDF. The method uses the MailMerge TX Text Control .NET Server for ASP.NET
DocumentServer Namespace
MailMerge Class
The MailMerge class is a .NET component that can be used to effortlessly merge template documents with database content in .NET projects, such as ASP.NET web applications, web services or Windows services.
class to merge the data into the template and embeds the ZUGFeRD XML into a PDF/A-3b document.

Loading...

The Sample

The console application creates a new Order and calls the above Invoice.Create method and writes the created PDF document to a file.

Loading...

After opening the PDF in Acrobat Reader, you can see the created visual representation and the embedded XML in the Attachments pane.

Invoice PDF

When loading this document into a ZUGFeRD validator (ZF/FX Validation), the results show a valid ZUGFeRD PDF.

Invoice PDF

You can download the sample from our GitHub repository to test this on your own.