feat(Hintergrund): Locate add, um die Position des Hintergrunds anhand anderer Anmerkungen zu berechnen.

- Standort des Hintergrunds zu Anmerkungen hinzugefügt
This commit is contained in:
Developer 02 2025-04-23 18:13:46 +02:00
parent e72ea534e5
commit d75da655d2
4 changed files with 57 additions and 19 deletions

View File

@ -64,7 +64,10 @@ public class AnnotationParams
var dict = _annots.ToDictionary(a => a.Name.ToLower(), a => a as IAnnotation);
if (Background is not null)
{
Background.Locate(_annots);
dict.Add(Background.Name.ToLower(), Background);
}
return dict;
}

View File

@ -20,4 +20,29 @@ public record Background : IAnnotation
public double Left { get; set; }
public double Top { get; set; }
public void Locate(IEnumerable<IAnnotation> annotations)
{
// set Top
if (annotations.MinBy(a => a.Top)?.Top is double minTop)
Top = minTop;
// set Left
if (annotations.MinBy(a => a.Left)?.Left is double minLeft)
Left = minLeft;
// set Width
if(annotations.MaxBy(a => a.GetRight())?.GetRight() is double maxRight)
Width = maxRight - Left;
// set Height
if (annotations.MaxBy(a => a.GetBottom())?.GetBottom() is double maxBottom)
Height = maxBottom - Top;
// add margins
Top -= Margin;
Left -= Margin;
Width += Margin * 2;
Height += Margin * 2;
}
}

View File

@ -0,0 +1,8 @@
namespace EnvelopeGenerator.Web.Models.Annotation;
public static class Extensions
{
public static double GetRight(this IAnnotation annotation) => annotation.Left + annotation?.Width ?? 0;
public static double GetBottom(this IAnnotation annotation) => annotation.Top + annotation?.Height ?? 0;
}

View File

@ -7,23 +7,28 @@ async function createAnnotations(document, instance) {
const page = element.page - 1
//background
const id_background = PSPDFKit.generateInstantId()
const annotation_background = new PSPDFKit.Annotations.WidgetAnnotation({
id: id_background,
pageIndex: page,
formFieldName: id_background,
backgroundColor: PSPDFKit.Color.WHITE,
blendMode: 'normal',
//boundingBox: new PSPDFKit.Geometry.Rect({width: 152, height: 180, left: 186.09992, top: 648.8533600000001}),
fontSize: 8,
})
if(annotParams.background){
const id_background = PSPDFKit.generateInstantId();
const annotation_background = new PSPDFKit.Annotations.WidgetAnnotation({
id: id_background,
pageIndex: page,
formFieldName: id_background,
backgroundColor: PSPDFKit.Color.WHITE,
blendMode: 'normal',
boundingBox: new PSPDFKit.Geometry.Rect(annotParams.background),
fontSize: 8,
});
const formFieldBackground = new PSPDFKit.FormFields.ButtonFormField({
name: id_background,
annotationIds: PSPDFKit.Immutable.List([annotation_background.id]),
value: "",
readOnly: false
});
const formFieldBackground = new PSPDFKit.FormFields.ButtonFormField({
name: id_background,
annotationIds: PSPDFKit.Immutable.List([annotation_background.id]),
value: "",
readOnly: false
})
signatures.push(annotation_background)
signatures.push(formFieldBackground)
}
//signatures
const id = PSPDFKit.generateInstantId()
@ -175,9 +180,6 @@ async function createAnnotations(document, instance) {
readOnly: true
})
signatures.push(annotation_background)
signatures.push(formFieldBackground)
signatures.push(annotation)
signatures.push(formField)
signatures.push(annotation_date)