feat(PDFBurner): support unstructured annotations and simplify processing
- Added `UnstructuredAnnotations` property to handle annotations without structured IDs - Changed default `hasStructuredID` to `False`, set to `True` only after successful parsing - Updated `AddInstantJSONAnnotationToPDF` to process annotations directly instead of grouping by receiver - Simplified logic for reversing annotations and applying seal positioning
This commit is contained in:
@@ -71,42 +71,39 @@ Namespace Jobs.FinalizeDocument
|
||||
Private Sub AddInstantJSONAnnotationToPDF(pInstantJSON As String)
|
||||
Dim oAnnotationData = JsonConvert.DeserializeObject(Of AnnotationData)(pInstantJSON)
|
||||
|
||||
For Each annots In oAnnotationData.AnnotationsByReceiver
|
||||
annots.Reverse()
|
||||
oAnnotationData.annotations.Reverse()
|
||||
Dim yPosOfSigAnnot = oAnnotationData.annotations.ElementAt(2).bbox.ElementAt(1) - 71.84002685546875 + 7
|
||||
Dim isSeal = True 'First element is signature seal
|
||||
|
||||
Dim yPosOfSigAnnot = annots.ElementAt(2).bbox.ElementAt(1) - 71.84002685546875 + 7
|
||||
Dim isSeal = True 'First element is signature seal
|
||||
Dim formFieldIndex = 0
|
||||
For Each oAnnotation In oAnnotationData.annotations
|
||||
Logger.Debug("Adding AnnotationID: " + oAnnotation.id)
|
||||
|
||||
Dim formFieldIndex = 0
|
||||
For Each oAnnotation In annots
|
||||
Logger.Debug("Adding AnnotationID: " + oAnnotation.id)
|
||||
Select Case oAnnotation.type
|
||||
Case ANNOTATION_TYPE_IMAGE
|
||||
|
||||
Select Case oAnnotation.type
|
||||
Case ANNOTATION_TYPE_IMAGE
|
||||
If (isSeal) Then
|
||||
oAnnotation.bbox.Item(1) = yPosOfSigAnnot
|
||||
End If
|
||||
|
||||
If (isSeal) Then
|
||||
oAnnotation.bbox.Item(1) = yPosOfSigAnnot
|
||||
End If
|
||||
AddImageAnnotation(oAnnotation, oAnnotationData.attachments)
|
||||
Exit Select
|
||||
|
||||
AddImageAnnotation(oAnnotation, oAnnotationData.attachments)
|
||||
Exit Select
|
||||
Case ANNOTATION_TYPE_INK
|
||||
AddInkAnnotation(oAnnotation)
|
||||
Exit Select
|
||||
|
||||
Case ANNOTATION_TYPE_INK
|
||||
AddInkAnnotation(oAnnotation)
|
||||
Exit Select
|
||||
Case ANNOTATION_TYPE_WIDGET
|
||||
'Add form field values
|
||||
Dim formFieldValue = oAnnotationData.formFieldValues.FirstOrDefault(Function(fv) fv.name = oAnnotation.id)
|
||||
If formFieldValue IsNot Nothing AndAlso Not _pdfBurnerParams.IgnoredLabels.Contains(formFieldValue.value) Then
|
||||
AddFormFieldValue(oAnnotation, formFieldValue, formFieldIndex)
|
||||
formFieldIndex += 1
|
||||
End If
|
||||
Exit Select
|
||||
End Select
|
||||
|
||||
Case ANNOTATION_TYPE_WIDGET
|
||||
'Add form field values
|
||||
Dim formFieldValue = oAnnotationData.formFieldValues.FirstOrDefault(Function(fv) fv.name = oAnnotation.id)
|
||||
If formFieldValue IsNot Nothing AndAlso Not _pdfBurnerParams.IgnoredLabels.Contains(formFieldValue.value) Then
|
||||
AddFormFieldValue(oAnnotation, formFieldValue, formFieldIndex)
|
||||
formFieldIndex += 1
|
||||
End If
|
||||
Exit Select
|
||||
End Select
|
||||
|
||||
isSeal = False
|
||||
Next
|
||||
isSeal = False
|
||||
Next
|
||||
|
||||
End Sub
|
||||
@@ -186,6 +183,15 @@ Namespace Jobs.FinalizeDocument
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public ReadOnly Property UnstructuredAnnotations As IEnumerable(Of List(Of Annotation))
|
||||
Get
|
||||
Return annotations _
|
||||
.Where(Function(annot) Not annot.hasStructuredID).ToList() _
|
||||
.GroupBy(Function(a) a.receiverId) _
|
||||
.Select(Function(g) g.ToList())
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public Property attachments As Dictionary(Of String, Attachment)
|
||||
Public Property formFieldValues As List(Of FormFieldValue)
|
||||
End Class
|
||||
@@ -202,7 +208,7 @@ Namespace Jobs.FinalizeDocument
|
||||
|
||||
Public internalType As String = Nothing
|
||||
|
||||
Public hasStructuredID As Boolean = True
|
||||
Public hasStructuredID As Boolean = False
|
||||
|
||||
Public Property id As String
|
||||
Get
|
||||
@@ -211,14 +217,13 @@ Namespace Jobs.FinalizeDocument
|
||||
Set(value As String)
|
||||
_id = value
|
||||
|
||||
If String.IsNullOrWhiteSpace(id) Then
|
||||
If String.IsNullOrWhiteSpace(_id) Then
|
||||
Throw New BurnAnnotationException("The identifier of annotation is null or empty.")
|
||||
End If
|
||||
|
||||
Dim parts As String() = value.Split("#"c)
|
||||
|
||||
If (parts.Length <> 4) Then
|
||||
hasStructuredID = False
|
||||
Return
|
||||
'Throw New BurnAnnotationException($"The identifier of annotation has more or less than 4 sub-part. Id: {_id}")
|
||||
End If
|
||||
@@ -236,6 +241,8 @@ Namespace Jobs.FinalizeDocument
|
||||
End If
|
||||
|
||||
internalType = parts(3)
|
||||
|
||||
hasStructuredID = True
|
||||
End Set
|
||||
End Property
|
||||
|
||||
|
||||
Reference in New Issue
Block a user