refactor(Pdf): Add Background-method to place a background behind the signatures.

This commit is contained in:
2025-09-26 16:00:25 +02:00
parent bf0bd8e9e7
commit 16657f6a31
5 changed files with 45 additions and 47 deletions

View File

@@ -10,8 +10,6 @@ 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;
@@ -224,21 +222,7 @@ public class EnvelopeController : ViewControllerBase
{
if (er.Envelope!.Documents?.FirstOrDefault() is DocumentDto doc && doc.ByteData is not null)
{
using var pdf = Pdf.FromMemory(doc.ByteData).Design(1, canvas =>
{
canvas.SetFillColor(new DeviceRgb(135, 62, 35));
canvas.Rectangle(100, 500, 200, 100);
canvas.Fill();
canvas.SetFillColor(new DeviceRgb(222, 220, 215));
canvas.SetStrokeColor(new DeviceRgb(135, 62, 35));
canvas.Circle(300, 500, 100);
canvas.FillStroke();
canvas.Fill();
});
using var pdf = Pdf.FromMemory(doc.ByteData).Background(doc.Elements!);
doc.ByteData = pdf.ExportAsBytes();

View File

@@ -5,35 +5,6 @@ async function createAnnotations(document) {
for (let element of document.elements) {
const annotParams = await getAnnotationParams(element.left, element.top);
const page = element.page - 1
//#region background
if (annotParams.background) {
let background = annotParams.background;
const id_background = PSPDFKit.generateInstantId();
const annotation_background = new PSPDFKit.Annotations.WidgetAnnotation({
id: id_background,
pageIndex: page,
formFieldName: id_background,
backgroundColor: background?.backgroundColor ? new PSPDFKit.Color(background.backgroundColor) : null,
blendMode: 'normal',
boundingBox: new PSPDFKit.Geometry.Rect(background),
fontSize: 8,
borderStyle: background.borderStyle,
borderWidth: background.borderWidth,
borderColor: background?.borderColor ? new PSPDFKit.Color(background.borderColor) : null
});
const formFieldBackground = new PSPDFKit.FormFields.ButtonFormField({
name: id_background,
annotationIds: PSPDFKit.Immutable.List([annotation_background.id]),
value: "",
readOnly: true
});
signatures.push(annotation_background)
signatures.push(formFieldBackground)
}
//#endregion
}
for (let element of document.elements) {

View File

@@ -72,6 +72,7 @@ async function getAnnotationParams(leftInInch = 0, topInInch = 0, inchToPointFac
annot.top += topInInch - 0.5;
annot.top *= inchToPointFactor;
}
return annotParams;
}