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:
@@ -56,7 +56,7 @@ public class PdfResultPackageService(
|
||||
converter.SaveDocument(convertedStream);
|
||||
convertedStream.Position = 0;
|
||||
|
||||
// Schritt 3: Anhang einbetten
|
||||
// Schritt 3: Hauptdokument laden
|
||||
using var processor = new PdfDocumentProcessor();
|
||||
processor.LoadDocument(convertedStream);
|
||||
|
||||
@@ -68,15 +68,23 @@ public class PdfResultPackageService(
|
||||
processor.Document.Subject = 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),
|
||||
Description = "Ergebnisbericht",
|
||||
MimeType = "application/pdf",
|
||||
Relationship = PdfAssociatedFileRelationship.Supplement,
|
||||
CreationDate = DateTime.Now,
|
||||
Data = File.ReadAllBytes(reportPath)
|
||||
});
|
||||
// Temporäres Dokument öffnen um Seitenanzahl zu ermitteln
|
||||
using var tempProcessor = new PdfDocumentProcessor();
|
||||
tempProcessor.LoadDocument(reportStream);
|
||||
reportPageCount = tempProcessor.Document.Pages.Count;
|
||||
|
||||
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
|
||||
var firstPage = processor.Document.Pages[0];
|
||||
@@ -126,10 +134,15 @@ public class PdfResultPackageService(
|
||||
processor.Document.Pages[0], 96, 96);
|
||||
}
|
||||
|
||||
// Schritt 4: Speichern
|
||||
// Schritt 5: Speichern
|
||||
try
|
||||
{
|
||||
processor.SaveDocument(outputPath);
|
||||
|
||||
logger.LogInformation(
|
||||
"Result-PDF erstellt mit {TotalPages} Seiten (Original + {ReportPages} Berichtseiten).",
|
||||
processor.Document.Pages.Count,
|
||||
reportPageCount);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user