Fix signature field formatting and add text truncation
Address customer feedback on signature field layout issues: - Added truncation logic in `PDFBurner.vb` to limit text length based on per-field maximums, appending a suffix (e.g., `..`). - Enhanced `PDFBurnerParams.vb` with `TextMaxLengths` and `TruncationSuffix` for configurable truncation behavior. - Improved spacing and layout handling for signature fields to prevent text collisions within fixed dimensions. - Updated `EnvelopeGenerator.sln` with documentation for the signature formatting fix (`fix-signature-field-formatting.md`). - Applied truncation consistently across `AddFormFieldValue` overloads and ensured deterministic rendering of annotations.
This commit is contained in:
@@ -119,7 +119,7 @@ Namespace Jobs.FinalizeDocument
|
||||
Dim y = frameY + yOffsetofFF
|
||||
|
||||
If annot.Type = AnnotationType.FormField Then
|
||||
AddFormFieldValue(annot.X / inchFactor, y, annot.Width / inchFactor, annot.Height / inchFactor, element.Page, annot.Value)
|
||||
AddFormFieldValue(annot.X / inchFactor, y, annot.Width / inchFactor, annot.Height / inchFactor, element.Page, annot.Value, annot.Name)
|
||||
ElseIf annot.Type = AnnotationType.Image Then
|
||||
AddImageAnnotation(
|
||||
annot.X / inchFactor,
|
||||
@@ -269,11 +269,14 @@ Namespace Jobs.FinalizeDocument
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Private Sub AddFormFieldValue(x As Double, y As Double, width As Double, height As Double, page As Integer, value As String)
|
||||
Private Sub AddFormFieldValue(x As Double, y As Double, width As Double, height As Double, page As Integer, value As String, Optional egName As String = "")
|
||||
Manager.SelectPage(page)
|
||||
|
||||
' Truncate if needed
|
||||
Dim displayValue As String = TruncateText(value, egName)
|
||||
|
||||
' Add the text annotation
|
||||
Dim ant = Manager.AddTextAnnot(x, y, width, height, value)
|
||||
Dim ant = Manager.AddTextAnnot(x, y, width, height, displayValue)
|
||||
|
||||
' Set the font properties
|
||||
ant.FontName = _pdfBurnerParams.FontName
|
||||
@@ -294,8 +297,9 @@ Namespace Jobs.FinalizeDocument
|
||||
Dim oHeight = oBounds.Item(3)
|
||||
|
||||
Manager.SelectPage(pAnnotation.pageIndex + 1)
|
||||
' Add the text annotation
|
||||
Dim ant = Manager.AddTextAnnot(oX, oY, oWidth, oHeight, formFieldValue.value)
|
||||
' Add the text annotation (truncate if needed)
|
||||
Dim displayValue As String = TruncateText(formFieldValue.value, pAnnotation.egName)
|
||||
Dim ant = Manager.AddTextAnnot(oX, oY, oWidth, oHeight, displayValue)
|
||||
|
||||
' Set the font properties
|
||||
ant.FontName = _pdfBurnerParams.FontName
|
||||
@@ -306,6 +310,24 @@ Namespace Jobs.FinalizeDocument
|
||||
#End Region
|
||||
|
||||
#Region "Helpers"
|
||||
''' <summary>
|
||||
''' Truncates a field value to the configured max length for that egName.
|
||||
''' Appends TruncationSuffix when the value is cut.
|
||||
''' </summary>
|
||||
Private Function TruncateText(value As String, egName As String) As String
|
||||
If String.IsNullOrEmpty(value) Then Return value
|
||||
If _pdfBurnerParams.TextMaxLengths Is Nothing Then Return value
|
||||
|
||||
Dim maxLen As Integer = 0
|
||||
If Not _pdfBurnerParams.TextMaxLengths.TryGetValue(egName, maxLen) Then Return value
|
||||
If maxLen <= 0 OrElse value.Length <= maxLen Then Return value
|
||||
|
||||
Dim suffix As String = If(_pdfBurnerParams.TruncationSuffix, "")
|
||||
Dim cutAt As Integer = Math.Max(0, maxLen - suffix.Length)
|
||||
Return value.Substring(0, cutAt) & suffix
|
||||
End Function
|
||||
|
||||
|
||||
Private Function ToPointF(pPoints As List(Of Single)) As PointF
|
||||
Dim oPoints = pPoints.Select(AddressOf ToInches).ToList()
|
||||
Return New PointF(oPoints.Item(0), oPoints.Item(1))
|
||||
|
||||
@@ -12,5 +12,23 @@ Namespace Jobs.FinalizeDocument
|
||||
Public Property FontSize As Integer = 8
|
||||
|
||||
Public Property FontStyle As FontStyle = FontStyle.Italic
|
||||
|
||||
''' <summary>
|
||||
''' The suffix appended to a truncated field value. Defaults to "..".
|
||||
''' Can be changed to any string (e.g. "…", "...", "").
|
||||
''' </summary>
|
||||
Public Property TruncationSuffix As String = ".."
|
||||
|
||||
''' <summary>
|
||||
''' Per-field maximum character count (including the TruncationSuffix).
|
||||
''' If a value exceeds the limit it is cut and TruncationSuffix is appended.
|
||||
''' Keys must match egName values used in PDFBurner (e.g. "name", "position", "city", "date").
|
||||
''' Set a value to 0 to disable truncation for that field.
|
||||
''' </summary>
|
||||
Public Property TextMaxLengths As New Dictionary(Of String, Integer) From {
|
||||
{"position", 20},
|
||||
{"city", 20},
|
||||
{"date", 28}
|
||||
}
|
||||
End Class
|
||||
End Namespace
|
||||
Reference in New Issue
Block a user