This commit is contained in:
Developer01 2025-04-24 16:00:29 +02:00
commit 5714c54385
3 changed files with 29 additions and 36 deletions

View File

@ -77,6 +77,8 @@ Public Class frmFinalizePDF
Dim oNewPath = Path.Combine(desktopPath, $"E{txtEnvelope.Text}R{txtReceiver.Text}.burned.pdf") Dim oNewPath = Path.Combine(desktopPath, $"E{txtEnvelope.Text}R{txtReceiver.Text}.burned.pdf")
File.WriteAllBytes(oNewPath, oNewBuffer) File.WriteAllBytes(oNewPath, oNewBuffer)
Process.Start(oNewPath)
Catch ex As Exception Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical) MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try End Try

View File

@ -170,7 +170,7 @@ Namespace Jobs
Throw New ApplicationException("Envelope could not be finalized") Throw New ApplicationException("Envelope could not be finalized")
End If End If
Catch ex As Exception Catch ex As Exception
Logger.Warn($"Unhandled exception while working envelope [{oId}] - [{ex.Message}]") Logger.Warn(ex, $"Unhandled exception while working envelope [{oId}]")
End Try End Try
@ -378,12 +378,10 @@ Namespace Jobs
Try Try
oInputDocumentBuffer = File.ReadAllBytes(oInputPath) oInputDocumentBuffer = File.ReadAllBytes(oInputPath)
Catch ex As Exception Catch ex As Exception
Logger.Error(ex)
Throw New BurnAnnotationException("Source document could not be read from disk!", ex) Throw New BurnAnnotationException("Source document could not be read from disk!", ex)
End Try End Try
End If End If
Return PDFBurner.BurnInstantJSONAnnotationsToPDF(oInputDocumentBuffer, oAnnotations) Return PDFBurner.BurnInstantJSONAnnotationsToPDF(oInputDocumentBuffer, oAnnotations)
End Function End Function

View File

@ -31,45 +31,38 @@ Namespace Jobs.FinalizeDocument
Public Function BurnInstantJSONAnnotationsToPDF(pSourceBuffer As Byte(), pInstantJSONList As List(Of String)) As Byte() Public Function BurnInstantJSONAnnotationsToPDF(pSourceBuffer As Byte(), pInstantJSONList As List(Of String)) As Byte()
Dim oResult As GdPictureStatus 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
Try ' Add annotation to PDF
Using oSourceStream As New MemoryStream(pSourceBuffer) For Each oJSON In pInstantJSONList
' Open PDF If AddInstantJSONAnnotationToPDF(oJSON) = False Then
oResult = Manager.InitFromStream(oSourceStream) Logger.Warn($"Error in AddInstantJSONAnnotationToPDF - oJson: ")
Logger.Warn(oJSON)
Throw New BurnAnnotationException($"Adding Annotation failed")
End If
Next
oResult = Manager.BurnAnnotationsToPage(RemoveInitialAnnots:=True, VectorMode:=True)
If oResult <> GdPictureStatus.OK Then
Throw New BurnAnnotationException($"Could not burn annotations to file: [{oResult}]")
End If
'Save PDF
Using oNewStream As New MemoryStream()
oResult = Manager.SaveDocumentToPDF(oNewStream)
If oResult <> GdPictureStatus.OK Then If oResult <> GdPictureStatus.OK Then
Throw New BurnAnnotationException($"Could not open document for burning: [{oResult}]") Throw New BurnAnnotationException($"Could not save document to stream: [{oResult}]")
End If End If
' Add annotation to PDF Manager.Close()
For Each oJSON In pInstantJSONList
If AddInstantJSONAnnotationToPDF(oJSON) = False Then
Logger.Warn($"Error in AddInstantJSONAnnotationToPDF - oJson: ")
Logger.Warn(oJSON)
Throw New BurnAnnotationException($"Adding Annotation failed")
End If
Next
oResult = Manager.BurnAnnotationsToPage(RemoveInitialAnnots:=True, VectorMode:=True)
If oResult <> GdPictureStatus.OK Then
Throw New BurnAnnotationException($"Could not burn annotations to file: [{oResult}]")
End If
'Save PDF Return oNewStream.ToArray()
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
Catch ex As Exception End Using
Logger.Error(ex)
Return Nothing
End Try
End Function End Function
Private Function AddInstantJSONAnnotationToPDF(pInstantJSON As String) As Boolean Private Function AddInstantJSONAnnotationToPDF(pInstantJSON As String) As Boolean