refactor(pdf): simplify and inline PDF merge logic in PdfMergeBehavior
- Removed MergeDocuments static method; integrated merge process directly in Handle() - Added null check for request.Report before merging - Cleaned up redundant return and improved flow for memory stream handling - Added DevExpress.XtraReports using directive - Clarified comment and exception messages for PDF loading and merging
This commit is contained in:
parent
2dfa1de7e1
commit
5b30465126
@ -1,4 +1,5 @@
|
|||||||
#if WINDOWS
|
#if WINDOWS
|
||||||
|
using DevExpress.XtraReports;
|
||||||
using EnvelopeGenerator.Application.Common.Extensions;
|
using EnvelopeGenerator.Application.Common.Extensions;
|
||||||
using EnvelopeGenerator.Application.Exceptions;
|
using EnvelopeGenerator.Application.Exceptions;
|
||||||
using EnvelopeGenerator.Domain.Constants;
|
using EnvelopeGenerator.Domain.Constants;
|
||||||
@ -24,28 +25,13 @@ public class PdfMergeBehavior : IPipelineBehavior<BurnPdfCommand, byte[]>
|
|||||||
{
|
{
|
||||||
var doc = await next(cancel);
|
var doc = await next(cancel);
|
||||||
|
|
||||||
doc = request.Report is byte[] report
|
if (request.Report is null)
|
||||||
? MergeDocuments(doc, report)
|
throw new InvalidOperationException("The final document report could not be merged." +
|
||||||
: throw new InvalidOperationException("The final document report could not be merged." +
|
|
||||||
"There may be an error related to the behavior register order." +
|
"There may be an error related to the behavior register order." +
|
||||||
"Request details:\n" + request.ToJson(Format.Json.ForDiagnostics));
|
"Request details:\n" + request.ToJson(Format.Json.ForDiagnostics));
|
||||||
|
|
||||||
string base64String = Convert.ToBase64String(doc);
|
using var oDocumentStream = new MemoryStream(doc);
|
||||||
|
using var oReportStream = new MemoryStream(request.Report);
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="pDocument"></param>
|
|
||||||
/// <param name="pReport"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
/// <exception cref="MergeDocumentException"></exception>
|
|
||||||
public static byte[] MergeDocuments(byte[] pDocument, byte[] pReport)
|
|
||||||
{
|
|
||||||
using var oDocumentStream = new MemoryStream(pDocument);
|
|
||||||
using var oReportStream = new MemoryStream(pReport);
|
|
||||||
using var oFinalStream = new MemoryStream();
|
using var oFinalStream = new MemoryStream();
|
||||||
using var oDocumentPDF = new GdPicturePDF();
|
using var oDocumentPDF = new GdPicturePDF();
|
||||||
using var oReportPDF = new GdPicturePDF();
|
using var oReportPDF = new GdPicturePDF();
|
||||||
@ -70,13 +56,17 @@ public class PdfMergeBehavior : IPipelineBehavior<BurnPdfCommand, byte[]>
|
|||||||
if (oStatus != GdPictureStatus.OK)
|
if (oStatus != GdPictureStatus.OK)
|
||||||
throw new MergeDocumentException($"Documents could not be merged: {oStatus}");
|
throw new MergeDocumentException($"Documents could not be merged: {oStatus}");
|
||||||
|
|
||||||
// Convert to PDF/A
|
// Convert to byte
|
||||||
oMergedPDF.SaveToStream(oFinalStream);
|
oMergedPDF.SaveToStream(oFinalStream);
|
||||||
oStatus = oDocumentPDF.GetStat();
|
oStatus = oDocumentPDF.GetStat();
|
||||||
if (oStatus != GdPictureStatus.OK)
|
if (oStatus != GdPictureStatus.OK)
|
||||||
throw new MergeDocumentException($"Document could not be converted to PDF/A: {oStatus}");
|
throw new MergeDocumentException($"Document could not be converted to PDF/A: {oStatus}");
|
||||||
|
|
||||||
return oFinalStream.ToArray();
|
doc = oFinalStream.ToArray();
|
||||||
|
|
||||||
|
string base64String = Convert.ToBase64String(doc);
|
||||||
|
|
||||||
|
return doc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
Loading…
x
Reference in New Issue
Block a user