diff --git a/EnvelopeGenerator.PdfEditor/Extensions.cs b/EnvelopeGenerator.PdfEditor/Extensions.cs new file mode 100644 index 00000000..26ebd97c --- /dev/null +++ b/EnvelopeGenerator.PdfEditor/Extensions.cs @@ -0,0 +1,42 @@ +using iText.Kernel.Colors; +using iText.Kernel.Pdf; +using iText.Kernel.Pdf.Canvas; + +#if NETFRAMEWORK +using System.IO; +using System; +#endif + +namespace EnvelopeGenerator.PdfEditor +#if NET + ; +#elif NETFRAMEWORK +{ +#endif + + public static class Extensions + { + public static TStream Edit(this TStream inputStream, Action edit) + where TStream : Stream, new() + { + using (var outputStream = new TStream()) + { + using (var pdfDoc = new PdfDocument(new PdfReader(inputStream), new PdfWriter(outputStream))) + { + edit(pdfDoc); + } + return outputStream; + } + } + + public static byte[] Edit(this byte[] pdfBytes, Action edit) + { + using (var inputStream = new MemoryStream(pdfBytes)) + { + return inputStream.Edit(edit).ToArray(); + } + } + } +#if NETFRAMEWORK +} +#endif \ No newline at end of file diff --git a/EnvelopeGenerator.Web/Controllers/EnvelopeController.cs b/EnvelopeGenerator.Web/Controllers/EnvelopeController.cs index 32523f45..bd2af8a9 100644 --- a/EnvelopeGenerator.Web/Controllers/EnvelopeController.cs +++ b/EnvelopeGenerator.Web/Controllers/EnvelopeController.cs @@ -1,9 +1,17 @@ using DigitalData.Core.Abstraction.Application.DTO; using DigitalData.Core.API; +using EnvelopeGenerator.Application.Common.Dto; +using EnvelopeGenerator.Application.Common.Dto.EnvelopeReceiver; +using EnvelopeGenerator.Application.Common.Extensions; +using EnvelopeGenerator.Application.Common.Interfaces.Services; using EnvelopeGenerator.Application.EnvelopeReceivers.Queries; using EnvelopeGenerator.Application.Resources; +using EnvelopeGenerator.Domain.Constants; +using EnvelopeGenerator.PdfEditor; using EnvelopeGenerator.Web.Extensions; using EnvelopeGenerator.Web.Models; +using iText.Kernel.Colors; +using iText.Kernel.Pdf.Canvas; using MediatR; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.Cookies; @@ -11,11 +19,6 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Localization; using Newtonsoft.Json; using OtpNet; -using EnvelopeGenerator.Domain.Constants; -using EnvelopeGenerator.Application.Common.Dto; -using EnvelopeGenerator.Application.Common.Dto.EnvelopeReceiver; -using EnvelopeGenerator.Application.Common.Extensions; -using EnvelopeGenerator.Application.Common.Interfaces.Services; namespace EnvelopeGenerator.Web.Controllers; @@ -221,6 +224,18 @@ public class EnvelopeController : ViewControllerBase { if (er.Envelope!.Documents?.FirstOrDefault() is DocumentDto doc && doc.ByteData is not null) { + doc.ByteData = doc.ByteData.Edit(doc => + { + var page = doc.GetFirstPage(); + var canvas = new PdfCanvas(page); + canvas.SetStrokeColor(ColorConstants.RED); + canvas.SetFillColor(ColorConstants.CYAN); + canvas.SetFillColorRgb(222, 220, 215); + canvas.SetLineWidth(2); + canvas.Rectangle(100, 500, 200, 100); + canvas.FillStroke(); + }); + ViewData["DocumentBytes"] = doc.ByteData; } else diff --git a/EnvelopeGenerator.Web/EnvelopeGenerator.Web.csproj b/EnvelopeGenerator.Web/EnvelopeGenerator.Web.csproj index b3c6b41a..7610c11c 100644 --- a/EnvelopeGenerator.Web/EnvelopeGenerator.Web.csproj +++ b/EnvelopeGenerator.Web/EnvelopeGenerator.Web.csproj @@ -2129,6 +2129,7 @@ +