fix: ensure annotations are properly burned after background addition in PDFBurner

This commit is contained in:
tekh 2025-10-28 10:43:19 +01:00
parent 75e47d10e3
commit 7041a4694a

View File

@ -51,9 +51,17 @@ Namespace Jobs.FinalizeDocument
Public Function BurnElementAnnotsToPDF(pSourceBuffer As Byte(), elements As List(Of Signature)) As Byte() Public Function BurnElementAnnotsToPDF(pSourceBuffer As Byte(), elements As List(Of Signature)) As Byte()
' Add background ' Add background
Using doc As Pdf(Of MemoryStream, MemoryStream) = Pdf.FromMemory(pSourceBuffer) Using doc As Pdf(Of MemoryStream, MemoryStream) = Pdf.FromMemory(pSourceBuffer)
Return doc.Background(elements).ExportStream().ToArray() pSourceBuffer = doc.Background(elements).ExportStream().ToArray()
End Using
Dim oResult As GdPictureStatus
Using oSourceStream As New MemoryStream(pSourceBuffer)
' Open PDF
oResult = Manager.InitFromStream(oSourceStream)
If oResult <> GdPictureStatus.OK Then
Throw New BurnAnnotationException($"Could not open document for burning: [{oResult}]")
End If
'Add annotations
For Each element In elements For Each element In elements
Dim x = ToInches(element.Left) Dim x = ToInches(element.Left)
@ -70,6 +78,19 @@ Namespace Jobs.FinalizeDocument
Next Next
Next Next
'Save PDF
Using oNewStream As New MemoryStream()
oResult = Manager.SaveDocumentToPDF(oNewStream)
If oResult <> GdPictureStatus.OK Then
Throw New BurnAnnotationException($"Could not save document to stream: [{oResult}]")
End If
Manager.Close()
Return oNewStream.ToArray()
End Using
End Using
End Using
End Function End Function
Public Function BurnInstantJSONAnnotsToPDF(pSourceBuffer As Byte(), pInstantJSONList As List(Of String)) As Byte() Public Function BurnInstantJSONAnnotsToPDF(pSourceBuffer As Byte(), pInstantJSONList As List(Of String)) As Byte()
@ -192,11 +213,10 @@ Namespace Jobs.FinalizeDocument
End Sub 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) 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 { Dim yOffset As New Dictionary(Of String, Integer) From {
{"position", 1}, {"position", 1},
{"date", 2}, {"date", 2},
{"city", 3}, {"city", 3}
} }
Manager.SelectPage(page + 1) Manager.SelectPage(page + 1)