feat(BurnPdfCommandHandler): add logging and implement BurnInstantJSONAnnotsToPDF
- Added ILogger<BurnPdfCommandHandler> to log warnings during annotation processing - Implemented BurnInstantJSONAnnotsToPDF method to handle instant JSON annotations - Added AddInstantJSONAnnotationToPDF stub for future implementation - Updated PDF burn flow to include error handling and logging
This commit is contained in:
@@ -3,10 +3,10 @@ using EnvelopeGenerator.Application.Common.Configurations;
|
||||
using EnvelopeGenerator.Application.Exceptions;
|
||||
using EnvelopeGenerator.Domain.Constants;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using EnvelopeGenerator.PdfEditor;
|
||||
using GdPicture14;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace EnvelopeGenerator.Application.Pdf;
|
||||
|
||||
@@ -31,17 +31,21 @@ public class BurnPdfCommandHandler : IRequestHandler<BurnPdfCommand>
|
||||
|
||||
private readonly IRepository<Signature> _signRepo;
|
||||
|
||||
private readonly ILogger<BurnPdfCommandHandler> _logger;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="pdfBurnerParams"></param>
|
||||
/// <param name="manager"></param>
|
||||
/// <param name="signRepo"></param>
|
||||
public BurnPdfCommandHandler(PDFBurnerParams pdfBurnerParams, AnnotationManager manager, IRepository<Signature> signRepo)
|
||||
/// <param name="logger"></param>
|
||||
public BurnPdfCommandHandler(PDFBurnerParams pdfBurnerParams, AnnotationManager manager, IRepository<Signature> signRepo, ILogger<BurnPdfCommandHandler> logger)
|
||||
{
|
||||
_pdfBurnerParams = pdfBurnerParams;
|
||||
_manager = manager;
|
||||
_signRepo = signRepo;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -162,6 +166,52 @@ public class BurnPdfCommandHandler : IRequestHandler<BurnPdfCommand>
|
||||
/// <param name="pInstantJSONList"></param>
|
||||
/// <returns></returns>
|
||||
public byte[] BurnInstantJSONAnnotsToPDF(byte[] pSourceBuffer, List<string> pInstantJSONList)
|
||||
{
|
||||
GdPictureStatus oResult;
|
||||
|
||||
using var oSourceStream = new MemoryStream(pSourceBuffer);
|
||||
// Open PDF
|
||||
oResult = _manager.InitFromStream(oSourceStream);
|
||||
if (oResult != GdPictureStatus.OK)
|
||||
{
|
||||
throw new BurnAnnotationException($"Could not open document for burning: [{oResult}]");
|
||||
}
|
||||
|
||||
// Add annotation to PDF
|
||||
foreach (var oJSON in pInstantJSONList)
|
||||
{
|
||||
try
|
||||
{
|
||||
AddInstantJSONAnnotationToPDF(oJSON);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Error in AddInstantJSONAnnotationToPDF - oJson: ");
|
||||
_logger.LogWarning(oJSON);
|
||||
throw new BurnAnnotationException("Adding Annotation failed", ex);
|
||||
}
|
||||
}
|
||||
|
||||
oResult = _manager.BurnAnnotationsToPage(RemoveInitialAnnots: true, VectorMode: true);
|
||||
if (oResult != GdPictureStatus.OK)
|
||||
{
|
||||
throw new BurnAnnotationException($"Could not burn annotations to file: [{oResult}]");
|
||||
}
|
||||
|
||||
// Save PDF
|
||||
using var oNewStream = new MemoryStream();
|
||||
oResult = _manager.SaveDocumentToPDF(oNewStream);
|
||||
if (oResult != GdPictureStatus.OK)
|
||||
{
|
||||
throw new BurnAnnotationException($"Could not save document to stream: [{oResult}]");
|
||||
}
|
||||
|
||||
_manager.Close();
|
||||
|
||||
return oNewStream.ToArray();
|
||||
}
|
||||
|
||||
private void AddInstantJSONAnnotationToPDF(string pInstantJSON)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user