diff --git a/EnvelopeGenerator.Application/Pdf/BurnPdfCommand.cs b/EnvelopeGenerator.Application/Pdf/BurnPdfCommand.cs index 120949c1..ab3ffa11 100644 --- a/EnvelopeGenerator.Application/Pdf/BurnPdfCommand.cs +++ b/EnvelopeGenerator.Application/Pdf/BurnPdfCommand.cs @@ -8,6 +8,7 @@ using GdPicture14; using MediatR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; +using Newtonsoft.Json; namespace EnvelopeGenerator.Application.Pdf; @@ -183,7 +184,8 @@ public class BurnPdfCommandHandler : IRequestHandler { try { - AddInstantJSONAnnotationToPDF(oJSON); + if (oJSON is string json) + AddInstantJsonAnnotationToPdf(json); } catch (Exception ex) { @@ -212,9 +214,42 @@ public class BurnPdfCommandHandler : IRequestHandler return oNewStream.ToArray(); } - private void AddInstantJSONAnnotationToPDF(string pInstantJSON) + private void AddInstantJsonAnnotationToPdf(string instantJson) { - throw new NotImplementedException(); + var annotationData = JsonConvert.DeserializeObject(instantJson); + + annotationData?.Annotations?.Reverse(); + + if (annotationData?.Annotations is null) + return; + + foreach (var annotation in annotationData.Annotations) + { + _logger.LogDebug("Adding AnnotationID: {id}", annotation.Id); + + switch (annotation.Type) + { + case AnnotationType.PSPDFKit.Image: + if (annotationData?.Attachments is not null) + AddImageAnnotation(annotation, annotationData.Attachments); + break; + + case AnnotationType.PSPDFKit.Ink: + AddInkAnnotation(annotation); + break; + + case AnnotationType.PSPDFKit.Widget: + // Add form field values + var formFieldValue = annotationData?.FormFieldValues? + .FirstOrDefault(fv => fv.Name == annotation.Id); + + if (formFieldValue != null && !_pdfBurnerParams.IgnoredLabels.Contains(formFieldValue.Value)) + { + AddFormFieldValue(annotation, formFieldValue); + } + break; + } + } } private void AddFormFieldValue(double x, double y, double width, double height, int page, string value)