using EnvelopeGenerator.Application.Common.Dto.PSPDFKitInstant; using EnvelopeGenerator.Domain.Constants; using GdPicture14; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using SixLabors.ImageSharp; using System.Drawing; using EnvelopeGenerator.Application.Common.Extensions; using EnvelopeGenerator.Application.Common.Interfaces.Model; using EnvelopeGenerator.Application.Common.Configurations; namespace EnvelopeGenerator.Application.Common.Extensions; /// /// /// public static class GdPictureExtensions { /// /// /// /// /// /// /// /// /// /// /// public static void AddFormFieldValue(this AnnotationManager manager, double x, double y, double width, double height, int page, string value, ITextStyle textStyle) { manager.SelectPage(page); // Add the text annotation var ant = manager.AddTextAnnot((float)x, (float)y, (float)width, (float)height, value); // Set the font properties ant.FontName = textStyle.FontName; ant.FontSize = textStyle.FontSize; ant.FontStyle = textStyle.FontStyle; manager.SaveAnnotationsToPage(); } /// /// /// /// /// /// /// public static void AddFormFieldValue(this AnnotationManager manager, Annotation pAnnotation, FormFieldValue formFieldValue, PDFBurnerParams options) { var ffIndex = options.GetAnnotationIndex(pAnnotation.EgName); // Convert pixels to Inches var oBounds = pAnnotation.Bbox?.Select(points => points.ToInches()).ToList(); if (oBounds is null || oBounds.Count < 4) return; double oX = oBounds[0]; double oY = oBounds[1] + options.YOffset * ffIndex + options.TopMargin; double oWidth = oBounds[2]; double oHeight = oBounds[3]; manager.SelectPage(pAnnotation.PageIndex + 1); // Add the text annotation var ant = manager.AddTextAnnot((float)oX, (float)oY, (float)oWidth, (float)oHeight, formFieldValue.Value); // Set the font properties ant.FontName = options.FontName; ant.FontSize = options.FontSize; ant.FontStyle = options.FontStyle; manager.SaveAnnotationsToPage(); } /// /// /// /// /// /// /// /// /// /// public static void AddImageAnnotation(this AnnotationManager manager, double x, double y, double width, double height, int page, string base64) { manager.SelectPage(page); manager.AddEmbeddedImageAnnotFromBase64(base64, (float)x, (float)y, (float)width, (float)height); } /// /// /// /// /// /// public static void AddImageAnnotation(this AnnotationManager manager, Annotation pAnnotation, Dictionary pAttachments) { var oAttachment = pAttachments .Where(a => a.Key == pAnnotation.ImageAttachmentId) .SingleOrDefault(); if (oAttachment.Value == null) return; // Convert pixels to Inches var oBounds = pAnnotation.Bbox?.Select(post => post.ToInches()).ToList(); if (oBounds is null || oBounds.Count < 4) return; var oX = oBounds[0]; var oY = oBounds[1]; var oWidth = oBounds[2]; var oHeight = oBounds[3]; manager.SelectPage(pAnnotation.PageIndex + 1); manager.AddEmbeddedImageAnnotFromBase64(oAttachment.Value.Binary, (float)oX, (float)oY, (float)oWidth, (float)oHeight); } /// /// /// /// /// /// public static void AddInkAnnotation(this AnnotationManager manager, int page, string value) { var ink = JsonConvert.DeserializeObject(value); var oSegments = ink?.Lines.Points; var oColor = ColorTranslator.FromHtml(ink?.StrokeColor ?? "#000000"); manager.SelectPage(page); if (oSegments is null) return; foreach (var oSegment in oSegments) { var oPoints = oSegment .Select(points => points.ToPointF()) .ToArray(); manager.AddFreeHandAnnot(oColor, oPoints); } } /// /// /// /// /// public static void AddInkAnnotation(this AnnotationManager manager, Annotation pAnnotation) { var oSegments = pAnnotation.Lines?.Points; var oColor = ColorTranslator.FromHtml(pAnnotation.StrokeColor ?? "#000000"); manager.SelectPage(pAnnotation.PageIndex + 1); if (oSegments is null) return; foreach (var oSegment in oSegments) { var oPoints = oSegment .Select(points => points.ToPointF()) .ToArray(); manager.AddFreeHandAnnot(oColor, oPoints); } } }