refactor(PDFBurner): Vereinfachung der PDFBurner-Annotationsmethoden und Verbesserung der Fehlerbehandlung

- Methoden für Annotationen (AddInstantJSONAnnotationToPDF, AddImageAnnotation, AddInkAnnotation, AddFormFieldValue) auf Rückgabe-Typ Void umgestellt.
- Interne Try/Catch-Blöcke und das Unterdrücken von Ausnahmen in Hilfsmethoden entfernt.
- Fehlerbehandlung in BurnInstantJSONAnnotationsToPDF zentralisiert, mit Try/Catch für das Hinzufügen von Annotationen.
- Exit Select-Anweisungen für bessere Lesbarkeit in Select Case-Blöcken hinzugefügt.
- Import von DevExpress.DataProcessing ergänzt.
This commit is contained in:
tekh 2025-10-06 10:29:29 +02:00
parent 42870b973d
commit df74267616
2 changed files with 76 additions and 100 deletions

View File

@ -563,6 +563,10 @@
<Project>{63e32615-0eca-42dc-96e3-91037324b7c7}</Project> <Project>{63e32615-0eca-42dc-96e3-91037324b7c7}</Project>
<Name>EnvelopeGenerator.Infrastructure</Name> <Name>EnvelopeGenerator.Infrastructure</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\EnvelopeGenerator.PdfEditor\EnvelopeGenerator.PdfEditor.csproj">
<Project>{211619f5-ae25-4ba5-a552-bacafe0632d3}</Project>
<Name>EnvelopeGenerator.PdfEditor</Name>
</ProjectReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

View File

@ -5,6 +5,7 @@ Imports DigitalData.Modules.Logging
Imports GdPicture14 Imports GdPicture14
Imports Newtonsoft.Json Imports Newtonsoft.Json
Imports EnvelopeGenerator.CommonServices.Jobs.FinalizeDocument.FinalizeDocumentExceptions Imports EnvelopeGenerator.CommonServices.Jobs.FinalizeDocument.FinalizeDocumentExceptions
Imports DevExpress.DataProcessing
Namespace Jobs.FinalizeDocument Namespace Jobs.FinalizeDocument
Public Class PDFBurner Public Class PDFBurner
@ -40,11 +41,13 @@ Namespace Jobs.FinalizeDocument
' Add annotation to PDF ' Add annotation to PDF
For Each oJSON In pInstantJSONList For Each oJSON In pInstantJSONList
If AddInstantJSONAnnotationToPDF(oJSON) = False Then Try
AddInstantJSONAnnotationToPDF(oJSON)
Catch ex As Exception
Logger.Warn($"Error in AddInstantJSONAnnotationToPDF - oJson: ") Logger.Warn($"Error in AddInstantJSONAnnotationToPDF - oJson: ")
Logger.Warn(oJSON) Logger.Warn(oJSON)
Throw New BurnAnnotationException($"Adding Annotation failed") Throw New BurnAnnotationException($"Adding Annotation failed", ex)
End If End Try
Next Next
oResult = Manager.BurnAnnotationsToPage(RemoveInitialAnnots:=True, VectorMode:=True) oResult = Manager.BurnAnnotationsToPage(RemoveInitialAnnots:=True, VectorMode:=True)
If oResult <> GdPictureStatus.OK Then If oResult <> GdPictureStatus.OK Then
@ -65,8 +68,7 @@ Namespace Jobs.FinalizeDocument
End Using End Using
End Function End Function
Private Function AddInstantJSONAnnotationToPDF(pInstantJSON As String) As Boolean Private Function AddInstantJSONAnnotationToPDF(pInstantJSON As String) As Void
Try
Dim oAnnotationData = JsonConvert.DeserializeObject(Of AnnotationData)(pInstantJSON) Dim oAnnotationData = JsonConvert.DeserializeObject(Of AnnotationData)(pInstantJSON)
oAnnotationData.annotations.Reverse() oAnnotationData.annotations.Reverse()
@ -86,9 +88,11 @@ Namespace Jobs.FinalizeDocument
End If End If
AddImageAnnotation(oAnnotation, oAnnotationData.attachments) AddImageAnnotation(oAnnotation, oAnnotationData.attachments)
Exit Select
Case ANNOTATION_TYPE_INK Case ANNOTATION_TYPE_INK
AddInkAnnotation(oAnnotation) AddInkAnnotation(oAnnotation)
Exit Select
Case ANNOTATION_TYPE_WIDGET Case ANNOTATION_TYPE_WIDGET
'Add form field values 'Add form field values
@ -97,21 +101,14 @@ Namespace Jobs.FinalizeDocument
AddFormFieldValue(oAnnotation, formFieldValue, formFieldIndex) AddFormFieldValue(oAnnotation, formFieldValue, formFieldIndex)
formFieldIndex += 1 formFieldIndex += 1
End If End If
Exit Select
End Select End Select
isSeal = False isSeal = False
Next Next
Return True
Catch ex As Exception
Logger.Warn("Could not create annotation from InstantJSON")
Logger.Error(ex)
Return False
End Try
End Function End Function
Private Function AddImageAnnotation(pAnnotation As Annotation, pAttachments As Dictionary(Of String, Attachment), Optional yOffset As Double = 0) As Boolean Private Function AddImageAnnotation(pAnnotation As Annotation, pAttachments As Dictionary(Of String, Attachment), Optional yOffset As Double = 0) As Void
Try
Dim oAttachment = pAttachments.Where(Function(a) a.Key = pAnnotation.imageAttachmentId). Dim oAttachment = pAttachments.Where(Function(a) a.Key = pAnnotation.imageAttachmentId).
SingleOrDefault() SingleOrDefault()
@ -125,18 +122,9 @@ Namespace Jobs.FinalizeDocument
Manager.SelectPage(pAnnotation.pageIndex + 1) Manager.SelectPage(pAnnotation.pageIndex + 1)
Manager.AddEmbeddedImageAnnotFromBase64(oAttachment.Value.binary, oX, oY, oWidth, oHeight) Manager.AddEmbeddedImageAnnotFromBase64(oAttachment.Value.binary, oX, oY, oWidth, oHeight)
Return True
Catch ex As Exception
Logger.Warn("Could not add image annotation!")
Logger.Error(ex)
Return False
End Try
End Function End Function
Private Function AddInkAnnotation(pAnnotation As Annotation) As Boolean Private Function AddInkAnnotation(pAnnotation As Annotation) As Void
Try
Dim oSegments = pAnnotation.lines.points Dim oSegments = pAnnotation.lines.points
Dim oColor = ColorTranslator.FromHtml(pAnnotation.strokeColor) Dim oColor = ColorTranslator.FromHtml(pAnnotation.strokeColor)
Manager.SelectPage(pAnnotation.pageIndex + 1) Manager.SelectPage(pAnnotation.pageIndex + 1)
@ -148,19 +136,9 @@ Namespace Jobs.FinalizeDocument
Manager.AddFreeHandAnnot(oColor, oPoints) Manager.AddFreeHandAnnot(oColor, oPoints)
Next Next
Return True
Catch ex As Exception
Logger.Warn("Could not add image annotation!")
Logger.Error(ex)
Return False
End Try
End Function End Function
Private Function AddFormFieldValue(pAnnotation As Annotation, formFieldValue As FormFieldValue, index As Integer) As Boolean Private Function AddFormFieldValue(pAnnotation As Annotation, formFieldValue As FormFieldValue, index As Integer) As Void
Try
' Convert pixels to Inches ' Convert pixels to Inches
Dim oBounds = pAnnotation.bbox.Select(AddressOf ToInches).ToList() Dim oBounds = pAnnotation.bbox.Select(AddressOf ToInches).ToList()
@ -178,12 +156,6 @@ Namespace Jobs.FinalizeDocument
ant.FontSize = _pdfBurnerParams.FontSize ant.FontSize = _pdfBurnerParams.FontSize
ant.FontStyle = _pdfBurnerParams.FontStyle ant.FontStyle = _pdfBurnerParams.FontStyle
Manager.SaveAnnotationsToPage() Manager.SaveAnnotationsToPage()
Return True
Catch ex As Exception
Logger.Warn("Could not add image annotation!")
Logger.Error(ex)
Return False
End Try
End Function End Function
Private Function ToPointF(pPoints As List(Of Single)) As PointF Private Function ToPointF(pPoints As List(Of Single)) As PointF