35 lines
1.0 KiB
C#
35 lines
1.0 KiB
C#
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
|
|
}
|
|
}
|
|
} |