Skip to content

Commit 01806eb

Browse files
github-actions[bot]KB Botdessyordanovadnikolov-prg
authored
Added new kb article embedding-xml-pdfa3b-zugferd-invoice-telerik-reporting-radpdfprocessing (#1778)
* Added new kb article embedding-xml-pdfa3b-zugferd-invoice-telerik-reporting-radpdfprocessing * Update embedding-xml-pdfa3b-zugferd-invoice-telerik-reporting-radpdfprocessing.md * Update embedding-xml-pdfa3b-zugferd-invoice-telerik-reporting-radpdfprocessing.md --------- Co-authored-by: KB Bot <[email protected]> Co-authored-by: Desislava Yordanova <[email protected]> Co-authored-by: Dimitar Nikolov <[email protected]>
1 parent 2c50c3b commit 01806eb

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
---
2+
title: Embedding a ZUGFeRD Invoice in a PDF Report
3+
description: Learn how to embed XML into PDF/A-3b (ZUGFeRD Invoice) using Telerik Reporting and RadPdfProcessing libraries.
4+
type: how-to
5+
page_title: How to Add XML to PDF/A-3b ZUGFeRD Invoice with Telerik Reporting and RadPdfProcessing
6+
meta_title: How to Add XML to PDF/A-3b ZUGFeRD Invoice with Telerik Reporting and RadPdfProcessing
7+
slug: embedding-zugferd-invoice-in-pdf-report
8+
tags: reporting, zugferd, invoice,xml, embed, compliance-level
9+
res_type: kb
10+
ticketid: 1695524
11+
---
12+
13+
## Environment
14+
15+
| Version | Product | Author |
16+
| ---- | ---- | ---- |
17+
| 2025.2.520| RadPdfProcessing |[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)|
18+
| 19.1.25.716 | Telerik Reporting|-|
19+
20+
## Description
21+
22+
This article demonstrates how to embed [ZUGFeRD](https://de.wikipedia.org/wiki/ZUGFeRD) (acronym for Zentraler User Guide des Forums elektronische Rechnung Deutschland) invoices to PDF reports combining **Telerik Reporting** and **Telerik Document Processing Libraries**.
23+
24+
## Solution
25+
26+
**Telerik Reporting** does not currently provide a built-in way to embed an XML file (such as the ZUGFeRD invoice) directly into the PDF during report generation. However, [RadPdfProcessing](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/overview), offered by the [Telerik Document Processing Libraries](https://docs.telerik.com/devtools/document-processing/introduction), provides such functionality out of the box.
27+
28+
The recommended workflow is:
29+
30+
1. [Generate the PDF Report using Telerik Reporting]({%slug telerikreporting/using-reports-in-applications/call-the-report-engine-via-apis/embedded-report-engine%}).
31+
1. [Import the PDF into RadPdfProcessing](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/formats-and-conversion/pdf/pdfformatprovider/pdfformatprovider#import).
32+
1. [Embed the ZUGFeRD XML file](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/features/embedded-file-streams/embedded-file-streams#creating-an-embedded-electronic-zugferd-invoice).
33+
1. [Export the final PDF](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/formats-and-conversion/pdf/pdfformatprovider/pdfformatprovider#export).
34+
35+
### Code Example
36+
37+
Here is a code snippet that demonstrates the process:
38+
39+
````C#
40+
using System.Diagnostics;
41+
using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf;
42+
using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export;
43+
using Telerik.Windows.Documents.Fixed.Model;
44+
45+
// Define paths for reports and PDFs
46+
string reportFolderPath = @"..\..\..\Reports\Storage";
47+
string pdfFolderPath = @"..\..\..\Reports\Pdf Files";
48+
string[] reportFiles = Directory.GetFiles(reportFolderPath);
49+
50+
foreach (string reportFilePath in reportFiles)
51+
{
52+
// Step 1: Generate PDF Report using Telerik Reporting
53+
var reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
54+
var deviceInfo = new System.Collections.Hashtable();
55+
56+
var reportSource = new Telerik.Reporting.UriReportSource();
57+
reportSource.Uri = reportFilePath;
58+
59+
Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport("PDF", reportSource, deviceInfo);
60+
string fileName = result.DocumentName + "_byReporting." + result.Extension;
61+
string filePath = pdfFolderPath + @"\" + fileName;
62+
63+
if (!result.HasErrors)
64+
{
65+
using (System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
66+
{
67+
fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
68+
}
69+
}
70+
71+
// Step 2: Import the PDF Report, add ZUGFeRD XML, and Export PDF using Telerik Document Processing
72+
string filePathToImport = pdfFolderPath + @"\" + fileName;
73+
74+
PdfFormatProvider pdfProvider = new PdfFormatProvider();
75+
RadFixedDocument fixedDocument = pdfProvider.Import(File.OpenRead(filePathToImport), TimeSpan.FromSeconds(10));
76+
77+
// Embed the ZUGFeRD XML file
78+
byte[] xmlBytes = File.ReadAllBytes(@"zugferd-invoice.xml");
79+
fixedDocument.EmbeddedFiles.AddZugferdInvoice(xmlBytes);
80+
81+
// Configure PDF export settings for compliance
82+
PdfExportSettings settings = new PdfExportSettings();
83+
settings.ComplianceLevel = PdfComplianceLevel.PdfA3B;
84+
pdfProvider.ExportSettings = settings;
85+
86+
// Export the final PDF
87+
string exportedFileName = result.DocumentName + "_byDPL." + result.Extension;
88+
filePath = pdfFolderPath + @"\" + exportedFileName;
89+
using (Stream output = File.OpenWrite(exportedFileName))
90+
{
91+
pdfProvider.Export(fixedDocument, output, TimeSpan.FromSeconds(10));
92+
}
93+
94+
Process.Start(new ProcessStartInfo { FileName = exportedFileName, UseShellExecute = true });
95+
}
96+
````
97+
98+
## See Also
99+
100+
* [RadPdfProcessing](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/overview)
101+
* [Embedding ZUGFeRD Invoices](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/features/embedded-file-streams/embedded-file-streams#creating-an-embedded-electronic-zugferd-invoice)

0 commit comments

Comments
 (0)