Create ZUGFeRD Invoices with C# – API and CLI Integration Examples
💻 Create ZUGFeRD Invoices with C# – API and CLI Integration Examples
Want to create ZUGFeRD-compliant invoices with your own C# application? No problem! With the 7-PDF Attach Extract and Remove tool and the integrated 7-PDF Invoice Extractor, you can automatically process PDF invoices into valid ZUGFeRD documents (PDF/A-3 with XML) using either the command line or REST API.
Important: To make a PDF invoice ZUGFeRD-compliant, the file must be in PDF/A-3 format. If your file isn’t, simply convert it beforehand using our 7-PDF Printer Professional.
🛠️ Workflow: From PDF to ZUGFeRD
- Create invoice as PDF/A-3 (e.g. with 7-PDF Printer)
- Process it using C# via CLI or API
- Generate ZUGFeRD XML and embed it into the PDF
🧪 Example 1: C# Console App Using CLI – Embed XML
This example uses the locally installed PDFAttachExtractAndRemoveFiles.exe
to embed an existing factur-x.xml
file into a PDF. No API token is required – ideal for tests and trial mode.
using System.Diagnostics; class Program { static void Main() { string attachToolPath = @"C:\Program Files (x86)\7-PDF\7-PDF Attach Extract And Remove Files\PDFAttachExtractAndRemoveFiles.exe"; string inputPdf = @"C:\Invoices\original.pdf"; string zugferdXml = @"C:\Invoices\factur-x.xml"; string args = $"-mode \"console\" -usage \"attach\" -inpdf \"{inputPdf}\" -infile \"{zugferdXml}\" -estandard \"ZF21\""; var proc = new Process(); proc.StartInfo.FileName = attachToolPath; proc.StartInfo.Arguments = args; proc.StartInfo.CreateNoWindow = true; proc.StartInfo.UseShellExecute = false; proc.Start(); proc.WaitForExit(); if (proc.ExitCode == 0) { Console.WriteLine("PDF successfully updated with ZUGFeRD XML."); } else { Console.WriteLine($"Error embedding XML. Exit code: {proc.ExitCode}"); } } }
Note: The tool 7-PDF Attach Extract and Remove must be installed locally. The trial version can be used directly (e.g. with an empty API token in print mode).
🔐 Example 2: C# with API Token – Analyze PDF & Get XML
This example sends the PDF invoice to the 7-PDF FastAPI. You’ll receive a full analysis and the generated ZUGFeRD XML. This variant requires a valid API token. With a license purchase, you’ll receive 25 free conversions included.
using System.Net.Http; using System.Net.Http.Headers; using System.Threading.Tasks; using System.IO; class Program { static async Task Main() { string pdfPath = @"C:\Invoices\original.pdf"; string apiToken = "YOUR_API_TOKEN"; // View token via https://generator.7-pdf.de/login var form = new MultipartFormDataContent(); var fileStream = File.OpenRead(pdfPath); var fileContent = new StreamContent(fileStream); fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/pdf"); form.Add(fileContent, "file", Path.GetFileName(pdfPath)); var client = new HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiToken); var response = await client.PostAsync("https://generator.7-pdf.de/extract-invoice/", form); var jsonResponse = await response.Content.ReadAsStringAsync(); dynamic parsed = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonResponse); File.WriteAllText("factur-x.xml", (string)parsed.xml); Console.WriteLine("ZUGFeRD XML saved as factur-x.xml"); } }
Try it now: Get API Access
📎 Add-on: Embed XML via CLI
PDFAttachExtractAndRemoveFiles.exe -mode "console" -usage "attach" -inpdf "original.pdf" -infile "factur-x.xml" -estandard "ZF21"
✅ The result is a ZUGFeRD-compliant PDF/A-3 e-invoice (DIN EN 16931).