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:
tekh 2025-10-08 16:27:28 +02:00
parent e96523b786
commit 57422a481c
4 changed files with 51 additions and 36 deletions

View File

@ -34,7 +34,7 @@ public class RemoveHistoryHandler : INotificationHandler<RemoveSignatureNotifica
await _repo.DeleteAsync(hists
=> hists
.Where(hist => hist.Envelope!.Uuid == notification.EnvelopeUuid)
.Where(hist => hist.Status == EnvelopeStatus.DocumentSigned)
, cancel);
.Where(hist => hist.Status == EnvelopeStatus.DocumentSigned),
cancel);
}
}

View File

@ -8,6 +8,7 @@ Imports Newtonsoft.Json.Linq
Imports DigitalData.Core.Abstraction.Application
Imports EnvelopeGenerator.Infrastructure
Imports Microsoft.EntityFrameworkCore
Imports System.Text
Public Class frmFinalizePDF
Private Const CONNECTIONSTRING = "Server=sDD-VMP04-SQL17\DD_DEVELOP01;Database=DD_ECM;User Id=sa;Password=+bk8oAbbQP1AzoHtvZUbd+Mbok2f8Fl4miEx1qssJ5yEaEWoQJ9prg4L14fURpPnqi1WMNs9fE4=;"
@ -104,7 +105,15 @@ Public Class frmFinalizePDF
Process.Start(oNewPath)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
Dim exMsg As StringBuilder = New StringBuilder(ex.Message).AppendLine()
Dim innerEx = ex.InnerException
While (innerEx IsNot Nothing)
exMsg.AppendLine(innerEx.Message)
innerEx = innerEx.InnerException
End While
MsgBox(exMsg.ToString(), MsgBoxStyle.Critical)
End Try
End Sub

View File

@ -71,14 +71,12 @@ Namespace Jobs.FinalizeDocument
Private Sub AddInstantJSONAnnotationToPDF(pInstantJSON As String)
Dim oAnnotationData = JsonConvert.DeserializeObject(Of AnnotationData)(pInstantJSON)
For Each annots In oAnnotationData.AnnotationsByReceiver
annots.Reverse()
Dim yPosOfSigAnnot = annots.ElementAt(2).bbox.ElementAt(1) - 71.84002685546875 + 7
oAnnotationData.annotations.Reverse()
Dim yPosOfSigAnnot = oAnnotationData.annotations.ElementAt(2).bbox.ElementAt(1) - 71.84002685546875 + 7
Dim isSeal = True 'First element is signature seal
Dim formFieldIndex = 0
For Each oAnnotation In annots
For Each oAnnotation In oAnnotationData.annotations
Logger.Debug("Adding AnnotationID: " + oAnnotation.id)
Select Case oAnnotation.type
@ -107,7 +105,6 @@ Namespace Jobs.FinalizeDocument
isSeal = False
Next
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

View File

@ -275,7 +275,6 @@ class App {
});
}
async validateAnnotations(totalSignatures) {
const annotations = await getAnnotations(this.pdfKit)
const filtered = annotations