refactor(BurnPdfCommandHandler): deserialize and process instant JSON annotations
- Added Newtonsoft.Json to parse instant JSON into `InstantData`. - Replaced `AddInstantJSONAnnotationToPDF` logic with `AddInstantJsonAnnotationToPdf`. - Process annotations by type (Image, Ink, Widget) and apply attachments/form fields. - Introduced checks for ignored form field values using `_pdfBurnerParams.IgnoredLabels`. - Added logging for annotation IDs when processing instant JSON.
This commit is contained in:
parent
7233d2ce98
commit
5fa358ca79
@ -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<BurnPdfCommand>
|
||||
{
|
||||
try
|
||||
{
|
||||
AddInstantJSONAnnotationToPDF(oJSON);
|
||||
if (oJSON is string json)
|
||||
AddInstantJsonAnnotationToPdf(json);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -212,9 +214,42 @@ public class BurnPdfCommandHandler : IRequestHandler<BurnPdfCommand>
|
||||
return oNewStream.ToArray();
|
||||
}
|
||||
|
||||
private void AddInstantJSONAnnotationToPDF(string pInstantJSON)
|
||||
private void AddInstantJsonAnnotationToPdf(string instantJson)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var annotationData = JsonConvert.DeserializeObject<InstantData>(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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user