How to make ZUGFeRD in FastReport .NET

2022-07-27

The ZUGFeRD standard was developed in Germany specifically to simplify the process of electronic invoicing. This standard allows you to exchange invoices without a preliminary agreement between the supplier and the recipient of the services or goods. In Germany, this standard extends to everywhere: in small, medium and large businesses, as well as in public institutions.

The name of the standard is the abbreviation ZUGFeRD. It stands for "The Unified User Guide developed by the German Forum on Electronic Invoices."

EDI (Data Interchange Electronic) - electronic document standard already used in Germany, but it is used only in large companies. The goal of ZUGFeRD is to cover all spheres of activity in the country, whether it be private enterprise or a large automotive concern. This standard is universal and not tied to a particular industry.

ZUGFeRD is based on the use of structured data. This is implemented using the XML standard. A human-readable account representation is implemented using the PDF / A standard. The PDF / A-3 format has the ability to include arbitrary types of objects in the document. Due to this, an XML representation of structured invoice data is included in the document. Thus, one document contains both a human-readable representation and a machine-readable one.


Advantages of ZUGFeRD before paper workflow:

  • • Saves paper;
  • • saves the time of document transfer;
  • • saves the human resource required to deliver the document;
  • • saves time searching for a document;
  • • Saves space for documents storage, because electronic;
  • • accelerates the process of payment of payment orders, which improves the liquidity of goods;
  • • significantly reduces the percentage of errors in documents, due to the automatic addition to accounting systems;
  • • eliminates the costs of manually adding to databases, thanks to integration with automated accounting systems;
  • • saves time for document approval, thanks to fast delivery.

ZUGFeRD supports the following account types:

ZUGFeRD Basic:

• Commercial invoices (invoices for goods and services) with code 380;

• Notifications (for example, requirements for payment of taxes by public authorities) with code 380;

• Commercial credit notes (for example, corrected invoices / cancellations) with a negative value (code 380).

ZUGFeRD Comfort also supports:

• Debit note regarding financial adjustments (code 84);

• A credit note associated with financial adjustments with a negative value (code 84).

ZUGFeRD Extended also supports:

• Self-evaluation accounts (credit note / self-billing procedure in accordance with tax legislation, code 389);

• Self-evaluation of credit notes with a negative value (code 389).

Now let's look at some details of the ZUGFeRD standard document. As noted above, an XML document is integrated into the PDF file for computer processing of invoices. It is also possible to include the XSD schema into a PDF document.

An XML file is always embedded in a PDF document with name "ZUGFeRD-invoice.xml". There is also the option to insert other documents explaining the invoice as additional files.

Here is a typical invoice in the form of an XML part of the ZUGFeRD document:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<ram:IncludedSupplyChainTradeLineItem>
<ram:AssociatedDocumentLineDocument>
<ram:LineID>1</ram:LineID>
</ram:AssociatedDocumentLineDocument>
<ram:SpecifiedSupplyChainTradeAgreement>
<ram:GrossPriceProductTradePrice>
<ram:ChargeAmount currencyID="EUR">1.0000</ram:ChargeAmount>
</ram:GrossPriceProductTradePrice>
<ram:NetPriceProductTradePrice>
<ram:ChargeAmount currencyID="EUR">1.0000</ram:ChargeAmount>
</ram:NetPriceProductTradePrice>
</ram:SpecifiedSupplyChainTradeAgreement>
<ram:SpecifiedSupplyChainTradeDelivery>
<ram:BilledQuantity unitCode="C62">100.0000</ram:BilledQuantity>
</ram:SpecifiedSupplyChainTradeDelivery>
<ram:SpecifiedSupplyChainTradeSettlement>
<ram:ApplicableTradeTax>
<ram:TypeCode>VAT</ram:TypeCode>
<ram:CategoryCode>S</ram:CategoryCode>
<ram:ApplicablePercent>19.00</ram:ApplicablePercent>
</ram:ApplicableTradeTax>
<ram:SpecifiedTradeSettlementMonetarySummation>
<ram:LineTotalAmount currencyID="EUR">100.00
</ram:LineTotalAmount>
</ram:SpecifiedTradeSettlementMonetarySummation>
</ram:SpecifiedSupplyChainTradeSettlement>
<ram:SpecifiedTradeProduct>
<ram:SellerAssignedID>ZS997</ram:SellerAssignedID>
<ram:Name>Citric acid 100 ml</ram:Name>
</ram:SpecifiedTradeProduct>
</ram:IncludedSupplyChainTradeLineItem>

 Let's now consider an example of using FastReport.Net to generate ZUGFeRD invoices. You can find it in the folder "J: \ Program Files (x86) \ FastReports \ FastReport.Net \ Demos \ C # \ ZUGFeRD". The project is a common WinForms application.

The form contains an input field and two buttons:

 

One of the buttons allows you to specify the path to the file using the standard file open dialog. The second button starts the procedure for generating the ZUGFeRD document.

Consider the code for the entire form class:

Program code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using FastReport;
using FastReport.Export.Pdf;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace ZUGFeRD
{
 public partial class MainForm : Form
 {
 private string appPath; // Path to the folder with the executable file of the application
 
 public MainForm()
 { 
 InitializeComponent();
 }
// The button for selecting the xml-file of ZUGFeRD format
 
 private void btnSelectFile_Click(object sender, EventArgs e)
 {
// Standard dialog for opening a file
 using (OpenFileDialog openDialog = new OpenFileDialog())
 {
 openDialog.Title = "Select ZUGFeRD XML";
 openDialog.InitialDirectory = appPath;
 openDialog.Filter = "ZUGFeRD invoice XML (*.xml)|*.xml|All files (*.*)|*.*";
 if (openDialog.ShowDialog() == DialogResult.OK)
 {
 tbZUGFeRDPath.Text = openDialog.FileName; // Assign the name of the selected file to the input field
 }
 }
 }
// Event of loading the main form of the program
 
 private void MainForm_Load(object sender, EventArgs e)
 {
 appPath = Path.GetDirectoryName(Application.ExecutablePath); // Specify the path to the folder with the executable file of the program
 }
 
// Button for creating a PDF document with the ZUGFeRD invoice
 private void btnCreatePDF_Click(object sender, EventArgs e)
 {
// Get the path to the xml file
 string xmlFile = File.Exists(tbZUGFeRDPath.Text) ? tbZUGFeRDPath.Text : Path.Combine(appPath, tbZUGFeRDPath.Text);
 if (File.Exists(xmlFile))
 {
// Get the path to the report file
 string reportFile = Path.Combine(appPath, "Invoice.frx");
 if (File.Exists(reportFile))
 {
// Call the standard file save dialog
 using (SaveFileDialog saveDialog = new SaveFileDialog())
 {
 saveDialog.Title = "Select path to save PDF file with embedded ZUGFeRD";
 saveDialog.Filter = "PDF/A-3b file (*.pdf)|*.pdf|All files (*.*)|*.*";
 saveDialog.FileName = "Invoice-With-ZUGFeRD.pdf";
 if (saveDialog.ShowDialog() == DialogResult.OK)
 {
 using (Report report = new Report()) //Create report object
 using (PDFExport pdf = new PDFExport()) //Create PDF export
 using (FileStream file = new FileStream(xmlFile, FileMode.Open, FileAccess.Read)) //Создаем поток
 {
 report.Load(reportFile); //Load report
 report.Prepare(); //Prepare report
 pdf.PdfCompliance = PDFExport.PdfStandard.PdfA_3b; //Set PDF file standard
 pdf.OpenAfterExport = true; //Open file after export
 pdf.AddEmbeddedXML("ZUGFeRD-invoice.xml", "ZUGFeRD invoice", DateTime.Now, file); //Include xml file into PDF document
 report.Export(pdf, saveDialog.FileName); //Execute export
 }
 }
 }
 }
 else
 MessageBox.Show("Report file does not exist!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
 }
 else
 MessageBox.Show("XML file does not exist!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
 }
 }
}

 From the comments to the code it is clear that we are performing the export of the pre-created report to PDF. In doing so, we set the PDF / A-3 standard and add the ZUGFeRD account file to the xml document.

Let's look at the report template, which is an invoice issued according to the ZUGFeRD standards.

 

To generate the XML representation of this report, you need to use the library, which can be found here: https://www.nuget.org/packages/ZUGFeRD-csharp/.

Using the code and ZUGFeRD-csharp library, we generate the following XML file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?xml version="1.0" encoding="UTF-8"?><rsm:CrossIndustryDocument xmlns:rsm="urn:ferd:CrossIndustryDocument:invoice:1p0" xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:12" xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:15" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <rsm:SpecifiedExchangedDocumentContext>
 <ram:TestIndicator>
 <udt:Indicator>true</udt:Indicator>
 </ram:TestIndicator>
 <ram:GuidelineSpecifiedDocumentContextParameter>
 <ram:ID>urn:ferd:CrossIndustryDocument:invoice:1p0:basic</ram:ID>
 </ram:GuidelineSpecifiedDocumentContextParameter>
 </rsm:SpecifiedExchangedDocumentContext>
 <rsm:HeaderExchangedDocument>
 <ram:ID>2017-415</ram:ID>
 <ram:Name>Rechnung</ram:Name>
 <ram:TypeCode>380</ram:TypeCode>
 <ram:IssueDateTime>
 <udt:DateTimeString format="102">20170320</udt:DateTimeString>
 </ram:IssueDateTime>
 <ram:IncludedNote>
 <ram:Content>Created by FastReport.Net https://www.fast-report.com</ram:Content>
 </ram:IncludedNote>
 </rsm:HeaderExchangedDocument>
 <rsm:SpecifiedSupplyChainTradeTransaction>
 
 <ram:ApplicableSupplyChainTradeAgreement>
 <ram:SellerTradeParty>
 <ram:Name>Haimerl Datentechnik</ram:Name>
 <ram:PostalTradeAddress>
 <ram:PostcodeCode>94356</ram:PostcodeCode>
 <ram:LineOne>Kreuzacker 10</ram:LineOne>
 <ram:CityName>Kirchroth / Kössnach</ram:CityName>
 <ram:CountryID>DE</ram:CountryID>
 </ram:PostalTradeAddress>
 <ram:SpecifiedTaxRegistration>
 <ram:ID schemeID="VA">DE179151914</ram:ID>
 </ram:SpecifiedTaxRegistration>
 </ram:SellerTradeParty>
 <ram:BuyerTradeParty>
 <ram:Name>ABB Lackieranlagen GmbH</ram:Name>
 <ram:PostalTradeAddress>
 <ram:PostcodeCode>35510</ram:PostcodeCode>
 <ram:LineOne>Schorbachstrasse 9</ram:LineOne>
 <ram:CityName>Butzbach</ram:CityName>
 <ram:CountryID>DE</ram:CountryID>
 </ram:PostalTradeAddress>
 </ram:BuyerTradeParty>
 </ram:ApplicableSupplyChainTradeAgreement>
 <ram:ApplicableSupplyChainTradeDelivery>
 <ram:ActualDeliverySupplyChainEvent>
 <ram:OccurrenceDateTime>
 <udt:DateTimeString format="102">20170320</udt:DateTimeString>
 </ram:OccurrenceDateTime>
 </ram:ActualDeliverySupplyChainEvent>
 </ram:ApplicableSupplyChainTradeDelivery>
 <ram:ApplicableSupplyChainTradeSettlement>
 <ram:PaymentReference>2017-415</ram:PaymentReference>
 <ram:InvoiceCurrencyCode>EUR</ram:InvoiceCurrencyCode>
 <ram:ApplicableTradeTax>
 <ram:CalculatedAmount currencyID="EUR">160.93</ram:CalculatedAmount>
 <ram:TypeCode>VAT</ram:TypeCode>
 <ram:BasisAmount currencyID="EUR">847.00</ram:BasisAmount>
 <ram:ApplicablePercent>19.0</ram:ApplicablePercent>
 </ram:ApplicableTradeTax>
 <ram:SpecifiedTradeSettlementMonetarySummation>
 <ram:LineTotalAmount currencyID="EUR">847.00</ram:LineTotalAmount>
 <ram:ChargeTotalAmount currencyID="EUR">0</ram:ChargeTotalAmount>
 <ram:AllowanceTotalAmount currencyID="EUR">0</ram:AllowanceTotalAmount>
 <ram:TaxBasisTotalAmount currencyID="EUR">847.00</ram:TaxBasisTotalAmount>
 <ram:TaxTotalAmount currencyID="EUR">160.93</ram:TaxTotalAmount>
 <ram:GrandTotalAmount currencyID="EUR">1007.93</ram:GrandTotalAmount>
 </ram:SpecifiedTradeSettlementMonetarySummation>
 </ram:ApplicableSupplyChainTradeSettlement>
 <ram:IncludedSupplyChainTradeLineItem>
 <ram:AssociatedDocumentLineDocument/>
 <ram:SpecifiedSupplyChainTradeDelivery>
 <ram:BilledQuantity unitCode="C62">1</ram:BilledQuantity>
 </ram:SpecifiedSupplyChainTradeDelivery>
 <ram:SpecifiedSupplyChainTradeSettlement/>
 <ram:SpecifiedTradeProduct>
 <ram:Name>FastReport.Net Professional Edition Single License</ram:Name>
 </ram:SpecifiedTradeProduct>
 </ram:IncludedSupplyChainTradeLineItem>
 <ram:IncludedSupplyChainTradeLineItem>
 <ram:AssociatedDocumentLineDocument/>
 <ram:SpecifiedSupplyChainTradeDelivery>
 <ram:BilledQuantity unitCode="C62">2</ram:BilledQuantity>
 </ram:SpecifiedSupplyChainTradeDelivery>
 <ram:SpecifiedSupplyChainTradeSettlement/>
 <ram:SpecifiedTradeProduct>
 <ram:Name>FastReport.Net Win+WebForms Edition Single License</ram:Name>
 </ram:SpecifiedTradeProduct>
 </ram:IncludedSupplyChainTradeLineItem>
 </rsm:SpecifiedSupplyChainTradeTransaction>
</rsm:CrossIndustryDocument>

 Run the program:

 

We select the xml-file of the invoice. Click on "Create PDF / A-3b with embedded XML". And this is how the human-readable representation of the document looks like, actually the PDF document itself:

 

 Thus, in order to use the xml view of ZUGFeRD in conjunction with the FastReport report, you only need to export the report in PDF A-3 and attach the xml file.

 

September 19, 2024

How to troubleshoot the most common issues when installing FastReport VCL

We have compiled a list of the most popular problems when installing FastReport VCL and have prepared detailed instructions on how to fix the problems that have arisen.
August 12, 2024

How to build and install the Postgres plugin in FastReport .NET

This article describes how to connect to the database using the FastReport .NET plugin for the report designer from Visual Studio via the NuGet server.
August 08, 2024

How to install FastReport .NET and its components on Windows

Step-by-step instructions for online and manual installation via the FastReport registration code.NET and its components in Windows.
Fast Reports
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 901 N Pitt Str #325 Alexandria VA 22314

© 1998-2024 Fast Reports Inc.