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
This commit is contained in:
parent
0ce7ae9494
commit
5e74de0ce7
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user