Add project files.
This commit is contained in:
35
DXApp.TemplateKitProject/Services/ZugferdExtractorService.cs
Normal file
35
DXApp.TemplateKitProject/Services/ZugferdExtractorService.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
namespace DXApp.TemplateKitProject.Services
|
||||
{
|
||||
using DevExpress.Pdf;
|
||||
using System.Text;
|
||||
|
||||
public class ZugferdExtractorService
|
||||
{
|
||||
private static readonly string[] KnownFileNames =
|
||||
[
|
||||
"zugferd-invoice.xml",
|
||||
"factur-x.xml",
|
||||
"xrechnung.xml"
|
||||
];
|
||||
|
||||
public string? ExtractXml(Stream pdfStream)
|
||||
{
|
||||
using var processor = new PdfDocumentProcessor();
|
||||
processor.LoadDocument(pdfStream);
|
||||
|
||||
foreach (var attachment in processor.Document.FileAttachments)
|
||||
{
|
||||
bool isZugferd = KnownFileNames.Any(name =>
|
||||
attachment.FileName.Equals(name, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (isZugferd || attachment.MimeType == "text/xml")
|
||||
{
|
||||
byte[] data = attachment.Data;
|
||||
return Encoding.UTF8.GetString(data);
|
||||
}
|
||||
}
|
||||
|
||||
return null; // Kein ZUGFeRD-Anhang gefunden
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user