From 5e74de0ce7bb93689e90221cd919e9311b2d5252 Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 28 Oct 2025 11:48:19 +0100 Subject: [PATCH] refactor(pdf-burner): adjust annotation positioning logic in BurnElementAnnotsToPDF - Introduced configurable inch factor, margins, width, and height for annotations - Added dynamic Y-offsets for form fields based on annotation names - Simplified AddFormFieldValue logic for direct coordinates - Removed hardcoded offsets previously embedded in the method --- .../Jobs/FinalizeDocument/PDFBurner.vb | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/EnvelopeGenerator.CommonServices/Jobs/FinalizeDocument/PDFBurner.vb b/EnvelopeGenerator.CommonServices/Jobs/FinalizeDocument/PDFBurner.vb index 397e2b06..1fb31e75 100644 --- a/EnvelopeGenerator.CommonServices/Jobs/FinalizeDocument/PDFBurner.vb +++ b/EnvelopeGenerator.CommonServices/Jobs/FinalizeDocument/PDFBurner.vb @@ -6,7 +6,6 @@ Imports DigitalData.Core.Abstraction.Application.Repository Imports DigitalData.Core.Abstractions Imports DigitalData.Modules.Base Imports DigitalData.Modules.Logging -Imports DocumentFormat.OpenXml.Drawing.Diagrams Imports EnvelopeGenerator.CommonServices.Jobs.FinalizeDocument.FinalizeDocumentExceptions Imports EnvelopeGenerator.Domain.Entities Imports EnvelopeGenerator.PdfEditor @@ -61,17 +60,31 @@ Namespace Jobs.FinalizeDocument Throw New BurnAnnotationException($"Could not open document for burning: [{oResult}]") End If + 'imported from background (add to configuration) + Dim inchFactor As Double = 72 + Dim magin As Double = 0.2 + Dim width As Double = 1.9500000000000002 * inchFactor + Dim height As Double = 2.52 * inchFactor + + Dim keys = {"position", "city", "date"} ' add to configuration + Dim unitYOffsets = 0.2 + Dim yOffsets = keys. + Select(Function(k, i) New With {Key .Key = k, Key .Value = unitYOffsets * i}). + ToDictionary(Function(x) x.Key, Function(x) x.Value) + 'Add annotations For Each element In elements - Dim x = ToInches(element.Left) - Dim y = ToInches(element.Top) + Dim x = (element.Left - 0.7 - magin) For Each annot In element.Annotations + Dim yOffset As Double = If(yOffsets.TryGetValue(annot.Name, yOffset), yOffset, 0) + Dim y = element.Top + yOffset + If annot.Type = AnnotationType.FormField Then - AddFormFieldValue(annot.Name, x, y, 100, 180, element.Page, annot.Value) + AddFormFieldValue(x, y, width, height, element.Page, annot.Value) ElseIf annot.Type = AnnotationType.FormField Then - AddImageAnnotation(x, y, 100, 180, element.Page, annot.Value) + AddImageAnnotation(x, y, width, height, element.Page, annot.Value) ElseIf annot.Type = AnnotationType.Ink Then AddInkAnnotation(element.Page, annot.Value) End If @@ -212,17 +225,11 @@ Namespace Jobs.FinalizeDocument Next End Sub - Private Sub AddFormFieldValue(name As String, x As Double, y As Double, width As Double, height As Double, page As Integer, value As String) - Dim yOffset As New Dictionary(Of String, Integer) From { - {"position", 1}, - {"date", 2}, - {"city", 3} - } - + Private Sub AddFormFieldValue(x As Double, y As Double, width As Double, height As Double, page As Integer, value As String) Manager.SelectPage(page) - Dim posY = y + _pdfBurnerParams.YOffset * yOffset(name) + ' Add the text annotation - Dim ant = Manager.AddTextAnnot(x, posY, width, height, value) + Dim ant = Manager.AddTextAnnot(x, y, width, height, value) ' Set the font properties ant.FontName = _pdfBurnerParams.FontName @@ -414,4 +421,4 @@ Namespace Jobs.FinalizeDocument End Class #End Region End Class -End Namespace +End Namespace \ No newline at end of file