feat(FinalizeDocument): aus CommonJobs kopiert, mit einfachen Fehlerbehebungen unter Verwendung von Copilot
- Programmiersprache von VSC zu C# geändert - Framework von .NET Framework zu .NET geändert
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
using System.IO;
|
||||
using DigitalData.Modules.Base;
|
||||
using DigitalData.Modules.Logging;
|
||||
using EnvelopeGenerator.ServiceHost.Exceptions;
|
||||
using GdPicture14;
|
||||
|
||||
namespace EnvelopeGenerator.ServiceHost.Jobs.FinalizeDocument;
|
||||
|
||||
public class PDFMerger : BaseClass
|
||||
{
|
||||
private readonly AnnotationManager _manager;
|
||||
private readonly LicenseManager _licenseManager;
|
||||
|
||||
private const bool AllowRasterization = true;
|
||||
private const bool AllowVectorization = true;
|
||||
|
||||
private readonly PdfConversionConformance _pdfaConformanceLevel = PdfConversionConformance.PDF_A_1b;
|
||||
|
||||
public PDFMerger(LogConfig logConfig, string gdPictureLicenseKey) : base(logConfig)
|
||||
{
|
||||
_licenseManager = new LicenseManager();
|
||||
_licenseManager.RegisterKEY(gdPictureLicenseKey);
|
||||
|
||||
_manager = new AnnotationManager();
|
||||
}
|
||||
|
||||
public byte[] MergeDocuments(byte[] document, byte[] report)
|
||||
{
|
||||
using var documentStream = new MemoryStream(document);
|
||||
using var reportStream = new MemoryStream(report);
|
||||
using var finalStream = new MemoryStream();
|
||||
using var documentPdf = new GdPicturePDF();
|
||||
using var reportPdf = new GdPicturePDF();
|
||||
|
||||
documentPdf.LoadFromStream(documentStream, true);
|
||||
var status = documentPdf.GetStat();
|
||||
if (status != GdPictureStatus.OK)
|
||||
{
|
||||
throw new MergeDocumentException($"Document could not be loaded: {status}");
|
||||
}
|
||||
|
||||
reportPdf.LoadFromStream(reportStream, true);
|
||||
status = reportPdf.GetStat();
|
||||
if (status != GdPictureStatus.OK)
|
||||
{
|
||||
throw new MergeDocumentException($"Report could not be loaded: {status}");
|
||||
}
|
||||
|
||||
var mergedPdf = documentPdf.Merge2Documents(documentPdf, reportPdf);
|
||||
status = mergedPdf.GetStat();
|
||||
if (status != GdPictureStatus.OK)
|
||||
{
|
||||
throw new MergeDocumentException($"Documents could not be merged: {status}");
|
||||
}
|
||||
|
||||
mergedPdf.ConvertToPDFA(finalStream, _pdfaConformanceLevel, AllowVectorization, AllowRasterization);
|
||||
status = documentPdf.GetStat();
|
||||
if (status != GdPictureStatus.OK)
|
||||
{
|
||||
throw new MergeDocumentException($"Document could not be converted to PDF/A: {status}");
|
||||
}
|
||||
|
||||
return finalStream.ToArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user