From 7041a4694a59d65894f56ec784514dac83399d02 Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 28 Oct 2025 10:43:19 +0100 Subject: [PATCH] fix: ensure annotations are properly burned after background addition in PDFBurner --- .../Jobs/FinalizeDocument/PDFBurner.vb | 54 +++++++++++++------ 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/EnvelopeGenerator.CommonServices/Jobs/FinalizeDocument/PDFBurner.vb b/EnvelopeGenerator.CommonServices/Jobs/FinalizeDocument/PDFBurner.vb index 23d2aa4b..cd00a88a 100644 --- a/EnvelopeGenerator.CommonServices/Jobs/FinalizeDocument/PDFBurner.vb +++ b/EnvelopeGenerator.CommonServices/Jobs/FinalizeDocument/PDFBurner.vb @@ -51,25 +51,46 @@ Namespace Jobs.FinalizeDocument Public Function BurnElementAnnotsToPDF(pSourceBuffer As Byte(), elements As List(Of Signature)) As Byte() ' Add background Using doc As Pdf(Of MemoryStream, MemoryStream) = Pdf.FromMemory(pSourceBuffer) - Return doc.Background(elements).ExportStream().ToArray() - End Using + pSourceBuffer = doc.Background(elements).ExportStream().ToArray() - For Each element In elements + 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 - Dim x = ToInches(element.Left) - Dim y = ToInches(element.Top) + 'Add annotations + For Each element In elements + + Dim x = ToInches(element.Left) + Dim y = ToInches(element.Top) + + For Each annot In element.Annotations + If annot.Type = AnnotationType.FormField Then + AddFormFieldValue(annot.Name, x, y, 100, 180, element.Page, annot.Value) + ElseIf annot.Type = AnnotationType.FormField Then + AddImageAnnotation(x, y, 100, 180, element.Page, annot.Value) + ElseIf annot.Type = AnnotationType.Ink Then + AddInkAnnotation(element.Page, annot.Value) + End If + 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 - For Each annot In element.Annotations - If annot.Type = AnnotationType.FormField Then - AddFormFieldValue(annot.Name, x, y, 100, 180, element.Page, annot.Value) - ElseIf annot.Type = AnnotationType.FormField Then - AddImageAnnotation(x, y, 100, 180, element.Page, annot.Value) - ElseIf annot.Type = AnnotationType.Ink Then - AddInkAnnotation(element.Page, annot.Value) - End If - Next - Next + Manager.Close() + Return oNewStream.ToArray() + End Using + End Using + End Using End Function Public Function BurnInstantJSONAnnotsToPDF(pSourceBuffer As Byte(), pInstantJSONList As List(Of String)) As Byte() @@ -192,11 +213,10 @@ Namespace Jobs.FinalizeDocument 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}, + {"city", 3} } Manager.SelectPage(page + 1)