# Generating a ZUGFeRD PDF with Existing XML Data using .NET C#

> This article shows how to generate a ZUGFeRD invoice with existing XML data using .NET C#. A valid PDF/A-3b file is created with a ZUGFeRD XML attachment using TX Text Control .NET Server.

- **Author:** Bjoern Meyer
- **Published:** 2024-07-25
- **Modified:** 2026-07-17
- **Description:** This article shows how to generate a ZUGFeRD invoice with existing XML data using .NET C#. A valid PDF/A-3b file is created with a ZUGFeRD XML attachment using TX Text Control .NET Server.
- **3 min read** (559 words)
- **Tags:**
  - ASP.NET
  - ASP.NET Core
  - ZUGFeRD
  - Electronic Invoicing
- **Web URL:** https://www.textcontrol.com/blog/2024/07/25/generating-a-zugferd-pdf-with-existing-xml-data-using-net-c-sharp/
- **LLMs URL:** https://www.textcontrol.com/blog/2024/07/25/generating-a-zugferd-pdf-with-existing-xml-data-using-net-c-sharp/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2024/07/25/generating-a-zugferd-pdf-with-existing-xml-data-using-net-c-sharp/llms-full.txt

---

ZUGFeRD and Factur-X are standardized formats for electronic invoices that combine a PDF document with embedded XML data. They are designed to facilitate the exchange of structured invoice data between businesses and public administrations, ensuring compatibility and compliance with German and European regulations. This hybrid format streamlines the billing process and reduces manual errors by providing easy human readability and machine processability.

### Generate PDF/A-3b

TX Text Control provides powerful PDF and document processing libraries to create these documents in the ISO standard PDF/A-3b format.

> **Learn More**
> 
> This article shows how to create valid XRechnung and ZUGFeRD invoices with ASP.NET Core C#. The invoice is created with the help MailMerge component and the ZUGFeRD-csharp library.
> 
> [Creating Valid XRechnung / ZUGFeRD Invoices with ASP.NET Core C# ](https://www.textcontrol.com/blog/2023/12/28/creating-valid-xrechnung-zugferd-invoices-with-asp-net-core-csharp/llms-full.txt)

### ZUGFeRD and Factur-X

This article focuses on creating valid PDF/A-3b ZUGFeRD invoices from existing XML data. Whether you use ERP systems or other applications that already generate valid ZUGFeRD XML, or whether you generate the required XML directly from your business objects, at the end of the day you need to produce a valid PDF document with the XML attached.

TX Text Control provides the required functionality to create these documents programmatically. The following code snippet shows how to create a PDF/A-3b document with an embedded ZUGFeRD XML attachment:

```
using TXTextControl;

SaveSettings saveSettings = new SaveSettings();

var metaData = File.ReadAllText("metadata.xml");

// byte array from the ZUGFeRD XML file
var zugferdXML = File.ReadAllBytes("yourzugferd.xml");

// create a new embedded file
var zugferdInvoice = new EmbeddedFile(
  "ZUGFeRD-invoice.xml",
  zugferdXML,
  metaData);

zugferdInvoice.Description = "ZUGFeRD-invoice";
zugferdInvoice.Relationship = "Alternative";
zugferdInvoice.MIMEType = "application/xml";
zugferdInvoice.LastModificationDate = DateTime.Now;

// set the embedded files
saveSettings.EmbeddedFiles = new EmbeddedFile[] { zugferdInvoice };

using (ServerTextControl tx = new ServerTextControl())
{
  tx.Create();

  tx.Text = "Invoice";

  // export the PDF
  tx.Save("invoice.pdf", StreamType.AdobePDFA, saveSettings);
}
```

In this code example, the visual version doesn't contain the actual invoice. In your application, the human-readable version would be generated from a template.

### Adding XMP Metadata

The *yourzugferd.xml* file in the code above would be your pre-created ZUGFeRD XML. By adding XMP metadata, ZUGFeRD ensures that both the human-readable PDF and the machine-readable XML data are properly linked and accessible. A typical metadata XML for ZUGFeRD would look like this:

```
<rdf:Description xmlns:pdfaExtension="http://www.aiim.org/pdfa/ns/extension/"
                       xmlns:pdfaField="http://www.aiim.org/pdfa/ns/field#"
                       xmlns:pdfaProperty="http://www.aiim.org/pdfa/ns/property#"
                       xmlns:pdfaSchema="http://www.aiim.org/pdfa/ns/schema#"
                       xmlns:pdfaType="http://www.aiim.org/pdfa/ns/type#"
                       rdf:about=""
                       >
  <pdfaExtension:schemas>
    <rdf:Bag>
      <rdf:li rdf:parseType="Resource">
        <pdfaSchema:schema>ZUGFeRD PDFA Extension Schema</pdfaSchema:schema>
        <pdfaSchema:namespaceURI>urn:zugferd:pdfa:CrossIndustryDocument:invoice:2p0#</pdfaSchema:namespaceURI>
        <pdfaSchema:prefix>fx</pdfaSchema:prefix>
        <pdfaSchema:property>
          <rdf:Seq>
            <rdf:li rdf:parseType="Resource">
              <pdfaProperty:name>DocumentFileName</pdfaProperty:name>
              <pdfaProperty:valueType>Text</pdfaProperty:valueType>
              <pdfaProperty:category>external</pdfaProperty:category>
              <pdfaProperty:description>name of the embedded XML invoice file</pdfaProperty:description>
            </rdf:li>
            <rdf:li rdf:parseType="Resource">
              <pdfaProperty:name>DocumentType</pdfaProperty:name>
              <pdfaProperty:valueType>Text</pdfaProperty:valueType>
              <pdfaProperty:category>external</pdfaProperty:category>
              <pdfaProperty:description>INVOICE</pdfaProperty:description>
            </rdf:li>
            <rdf:li rdf:parseType="Resource">
              <pdfaProperty:name>Version</pdfaProperty:name>
              <pdfaProperty:valueType>Text</pdfaProperty:valueType>
              <pdfaProperty:category>external</pdfaProperty:category>
              <pdfaProperty:description>The actual version of the ZUGFeRD data</pdfaProperty:description>
            </rdf:li>
            <rdf:li rdf:parseType="Resource">
              <pdfaProperty:name>ConformanceLevel</pdfaProperty:name>
              <pdfaProperty:valueType>Text</pdfaProperty:valueType>
              <pdfaProperty:category>external</pdfaProperty:category>
              <pdfaProperty:description>The conformance level of the ZUGFeRD data</pdfaProperty:description>
            </rdf:li>
          </rdf:Seq>
        </pdfaSchema:property>
      </rdf:li>
    </rdf:Bag>
  </pdfaExtension:schemas>
</rdf:Description>
<rdf:Description xmlns:fx="urn:zugferd:pdfa:CrossIndustryDocument:invoice:2p0#"
                 fx:ConformanceLevel="EN 16931"
                 fx:DocumentFileName="zugferd-invoice.xml"
                 fx:DocumentType="INVOICE"
                 fx:Version="2p0"
                 rdf:about=""/>
```

When opening in Adobe Acrobat Reader, the ZUGFeRD XML data is displayed in the attachments panel:

![Creating ZUGFeRD documents with TX Text Control](https://s1-www.textcontrol.com/assets/dist/blog/2024/07/25/a/assets/zugferd.webp "Creating ZUGFeRD documents with TX Text Control")

The XMP metadata can be viewed in the document properties:

![Creating ZUGFeRD documents with TX Text Control](https://s1-www.textcontrol.com/assets/dist/blog/2024/07/25/a/assets/metadata.webp "Creating ZUGFeRD documents with TX Text Control")

### Conclusion

Creating ZUGFeRD and Factur-X invoices is a common requirement for many businesses. TX Text Control provides the required functionality to create these documents programmatically. The PDF/A-3b format ensures that the document is compliant with the ISO standard for long-term archiving and the ZUGFeRD XML data is properly linked and accessible.

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [Why Structured E-Invoices Still Need Tamper Protection using C# and .NET](https://www.textcontrol.com/blog/2026/03/24/why-structured-e-invoices-still-need-tamper-protection-using-csharp-and-dotnet/llms.txt)
- [Visualize and Preview XRechnung, ZUGFeRD, and Factur-X Documents in .NET C#](https://www.textcontrol.com/blog/2025/01/02/visualize-and-preview-xrechnung-zugferd-and-factur-x-documents-in-net-csharp/llms.txt)
- [Creating ZUGFeRD 2.3 (XRechnung, Factur-X) Documents with .NET C#](https://www.textcontrol.com/blog/2025/01/02/creating-zugferd-2-3-xrechnung-factur-x-documents-with-net-c-sharp/llms.txt)
- [Using XRechnung / ZUGFeRD XML to Create PDF/A-3b Invoices with ASP.NET Core C#](https://www.textcontrol.com/blog/2024/09/23/using-xrechnung-zugferd-xml-to-create-pdf-a-3b-invoices-with-asp-net-core-c-sharp/llms.txt)
- [Silicon Valley, Here We Come!](https://www.textcontrol.com/blog/2026/08/10/silicon-valley-here-we-come/llms.txt)
- [Against the Trend: Why We Still Believe in Transparent, Perpetual Software Licensing. And Why You Should Too](https://www.textcontrol.com/blog/2026/08/06/against-the-trend-transparent-perpetual-software-licensing/llms.txt)
- [Unlock the Full Value of Your TX Text Control License](https://www.textcontrol.com/blog/2026/08/06/unlock-the-full-value-of-your-tx-text-control-license/llms.txt)
- [Introducing TX Text Control Web Collaboration Preview for ASP.NET Core](https://www.textcontrol.com/blog/2026/08/05/introducing-tx-text-control-web-collaboration-preview-for-asp-net-core-document-editors/llms.txt)
- [Building Long-Term Trust with Digital Signatures and Timestamps in C# .NET](https://www.textcontrol.com/blog/2026/08/04/building-long-term-trust-with-digital-signatures-and-timestamps-in-c-sharp-dot-net/llms.txt)
- [AI Natural Language Document Generation with MCP and TX Text Control .NET](https://www.textcontrol.com/blog/2026/07/16/ai-natural-language-document-generation-with-mcp-server-and-tx-text-control-dotnet/llms.txt)
- [WeAreDevelopers World Congress Europe 2026 Wrap Up: Record Breaking Days in Berlin](https://www.textcontrol.com/blog/2026/07/13/wearedevelopers-world-congress-europe-2026-wrap-up-record-breaking-days-in-berlin/llms.txt)
- [C# Document Generation: A Developer's Guide for .NET](https://www.textcontrol.com/blog/2026/07/08/csharp-document-generation-developer-guide-for-dotnet/llms.txt)
- [Validating PDF/UA Documents in .NET C#: A Practical Guide](https://www.textcontrol.com/blog/2026/07/06/validating-pdf-ua-documents-in-dotnet-csharp/llms.txt)
- [See Text Control at WeAreDevelopers World Congress Europe 2026 in Berlin](https://www.textcontrol.com/blog/2026/07/06/see-text-control-at-wearedevelopers-world-congress-europe-2026-in-berlin/llms.txt)
- [DWX 2026 Wrap-Up: Four Days of Innovation, Conversations, and Enterprise Document Solutions](https://www.textcontrol.com/blog/2026/07/03/dwx-2026-wrap-up-four-days-of-innovation-conversations-and-enterprise-document-solutions/llms.txt)
- [Create SignFabric Envelopes from Mail Merge Templates in .NET C#](https://www.textcontrol.com/blog/2026/06/23/create-signfabric-envelopes-from-mail-merge-templates-using-dotnet-csharp/llms.txt)
- [Convert SSRS RDL Reports to DOCX and TX Text Control Templates in .NET C#](https://www.textcontrol.com/blog/2026/06/22/convert-ssrs-rdl-reports-to-docx-and-tx-text-control-templates-in-dotnet-csharp/llms.txt)
- [Export Document Tables to CSV in .NET C#](https://www.textcontrol.com/blog/2026/06/19/export-document-tables-to-csv-in-dotnet-csharp/llms.txt)
- [Major SignFabric Updates: Stronger Audit Trails, Validation, and Recipient Workflows](https://www.textcontrol.com/blog/2026/06/17/major-signfabric-updates-stronger-audit-trails-validation-and-recipient-workflows/llms.txt)
- [Text Control Expands North American Conference Presence with WeAreDevelopers World Congress North America](https://www.textcontrol.com/blog/2026/06/12/text-control-expands-north-american-conference-presence-with-wearedevelopers-world-congress-north-america/llms.txt)
- [Converting HTML to Markdown in C# .NET](https://www.textcontrol.com/blog/2026/06/11/converting-html-to-markdown-in-csharp-dot-net/llms.txt)
- [Beyond WebSockets: A Glimpse into the Future of Document Editing with WebAssembly](https://www.textcontrol.com/blog/2026/06/10/beyond-websockets-glimpse-future-document-editing-webassembly/llms.txt)
- [Showcasing the Future of Document Processing at Developer World DWX 2026](https://www.textcontrol.com/blog/2026/06/08/showcasing-the-future-of-document-processing-at-dwx-developer-week-2026/llms.txt)
- [PDF Security Explained: Passwords, Permissions, Encryption and Digital Signatures in C# .NET](https://www.textcontrol.com/blog/2026/06/08/pdf-security-explained-passwords-permissions-encryption-and-digital-signatures-in-csharp-dotnet/llms.txt)
- [NDC Copenhagen 2026: Great Days in the Heart of Copenhagen's Developer Community](https://www.textcontrol.com/blog/2026/06/05/ndc-copenhagen-2026-great-days-in-the-heart-of-copenhagens-developer-community/llms.txt)
