Add PDF/A compliance checks and warnings
Added `PdfALevel` and `PdfAWarning` properties to the `PdfExtractionResult` class to store the PDF/A compliance level and indicate if a warning should be displayed for non-compliance. Updated `Upload.cshtml` to display the PDF/A compliance level and conditionally show a warning message if the document is not PDF/A compliant. Enhanced `PdfAttachmentExtractorService` to determine the PDF/A compliance level using `PdfDocumentProcessor`, map it to a string representation, and log the compliance level. Added logic to set `PdfAWarning` for non-compliant documents.
This commit is contained in:
@@ -9,6 +9,14 @@ public class PdfExtractionResult
|
|||||||
Attachments.FirstOrDefault(a => a.IsZugferdXml);
|
Attachments.FirstOrDefault(a => a.IsZugferdXml);
|
||||||
|
|
||||||
public bool HasZugferdXml => ZugferdXmlAttachment is not null;
|
public bool HasZugferdXml => ZugferdXmlAttachment is not null;
|
||||||
|
|
||||||
|
// Welche PDF/A-Stufe hat das Dokument?
|
||||||
|
// Beispiel: "PDF/A-3b", "PDF/A-2b", oder "Kein PDF/A"
|
||||||
|
public string PdfALevel { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
// Soll eine Warnung angezeigt werden?
|
||||||
|
// true wenn kein PDF/A → ZUGFeRD-Rechnungen müssen PDF/A-3b sein
|
||||||
|
public bool PdfAWarning { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ExtractedAttachment
|
public class ExtractedAttachment
|
||||||
|
|||||||
@@ -42,6 +42,15 @@
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@* PDF/A-Konformitätsstufe anzeigen *@
|
||||||
|
<div class="alert @(Model.Result.PdfAWarning ? "alert-warning" : "alert-info") mt-2">
|
||||||
|
<strong>PDF/A-Konformität:</strong> @Model.Result.PdfALevel
|
||||||
|
@if (Model.Result.PdfAWarning)
|
||||||
|
{
|
||||||
|
<span> – ⚠️ ZUGFeRD-Rechnungen müssen PDF/A-3b sein.</span>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
<table class="table table-sm table-bordered">
|
<table class="table table-sm table-bordered">
|
||||||
<thead class="table-light">
|
<thead class="table-light">
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -26,6 +26,22 @@ public class PdfAttachmentExtractorService(
|
|||||||
using var processor = new PdfDocumentProcessor();
|
using var processor = new PdfDocumentProcessor();
|
||||||
processor.LoadDocument(pdfStream);
|
processor.LoadDocument(pdfStream);
|
||||||
|
|
||||||
|
// PDF/A-Konformität prüfen
|
||||||
|
var compatibility = processor.Document.PdfACompatibility;
|
||||||
|
result.PdfALevel = compatibility switch
|
||||||
|
{
|
||||||
|
PdfACompatibility.None => "Kein PDF/A",
|
||||||
|
PdfACompatibility.PdfA1b => "PDF/A-1b",
|
||||||
|
PdfACompatibility.PdfA2b => "PDF/A-2b",
|
||||||
|
PdfACompatibility.PdfA3b => "PDF/A-3b",
|
||||||
|
_ => compatibility.ToString()
|
||||||
|
};
|
||||||
|
result.PdfAWarning = compatibility == PdfACompatibility.None;
|
||||||
|
|
||||||
|
logger.LogInformation(
|
||||||
|
"PDF '{FileName}': Konformität = {Level}",
|
||||||
|
sourceFileName, result.PdfALevel);
|
||||||
|
|
||||||
// Fix: .ToList() → IEnumerable → List<T> mit Count-Property
|
// Fix: .ToList() → IEnumerable → List<T> mit Count-Property
|
||||||
var attachments = processor.Document.FileAttachments.ToList();
|
var attachments = processor.Document.FileAttachments.ToList();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user