Enhance PDF processing and report integration

Refactor `PdfResultPackageService` to improve PDF handling:
- Load the main document into `PdfDocumentProcessor`.
- Remove original metadata to attribute the result to `DXApp`.
- Replace report file attachment with appending report pages.
- Use a temporary processor to determine report page count.
- Add logging for appended pages and total page count.
- Update save operation to include detailed logging.

Removed the functionality to attach the report file as a PDF attachment.
Improved overall usability, traceability, and document attribution.
This commit is contained in:
OlgunR
2026-06-02 14:06:24 +02:00
parent 03599addb8
commit 43d63e975d

View File

@@ -56,7 +56,7 @@ public class PdfResultPackageService(
converter.SaveDocument(convertedStream); converter.SaveDocument(convertedStream);
convertedStream.Position = 0; convertedStream.Position = 0;
// Schritt 3: Anhang einbetten // Schritt 3: Hauptdokument laden
using var processor = new PdfDocumentProcessor(); using var processor = new PdfDocumentProcessor();
processor.LoadDocument(convertedStream); processor.LoadDocument(convertedStream);
@@ -68,15 +68,23 @@ public class PdfResultPackageService(
processor.Document.Subject = string.Empty; processor.Document.Subject = string.Empty;
processor.Document.Keywords = string.Empty; processor.Document.Keywords = string.Empty;
processor.AttachFile(new PdfFileAttachment // Schritt 3a: Berichts-Seiten ans Ende anhängen
int reportPageCount;
using (var reportStream = new FileStream(reportPath, FileMode.Open, FileAccess.Read))
{ {
FileName = Path.GetFileName(reportPath), // Temporäres Dokument öffnen um Seitenanzahl zu ermitteln
Description = "Ergebnisbericht", using var tempProcessor = new PdfDocumentProcessor();
MimeType = "application/pdf", tempProcessor.LoadDocument(reportStream);
Relationship = PdfAssociatedFileRelationship.Supplement, reportPageCount = tempProcessor.Document.Pages.Count;
CreationDate = DateTime.Now,
Data = File.ReadAllBytes(reportPath) logger.LogDebug(
}); "Hänge {PageCount} Seite(n) aus Bericht an das Dokument an.",
reportPageCount);
// Stream zurücksetzen und ans Hauptdokument anhängen
reportStream.Position = 0;
processor.AppendDocument(reportStream);
}
// Schritt 4: Stempel auf Seite 1 zeichnen // Schritt 4: Stempel auf Seite 1 zeichnen
var firstPage = processor.Document.Pages[0]; var firstPage = processor.Document.Pages[0];
@@ -126,10 +134,15 @@ public class PdfResultPackageService(
processor.Document.Pages[0], 96, 96); processor.Document.Pages[0], 96, 96);
} }
// Schritt 4: Speichern // Schritt 5: Speichern
try try
{ {
processor.SaveDocument(outputPath); processor.SaveDocument(outputPath);
logger.LogInformation(
"Result-PDF erstellt mit {TotalPages} Seiten (Original + {ReportPages} Berichtseiten).",
processor.Document.Pages.Count,
reportPageCount);
} }
catch (Exception ex) catch (Exception ex)
{ {