fix für PDF-Attachment bei MergePDFs
This commit is contained in:
@@ -2458,9 +2458,15 @@ Public Class DATENVERVER_OPTIONS
|
||||
|
||||
Using pdf As New iText.Kernel.Pdf.PdfDocument(New iText.Kernel.Pdf.PdfReader(pdfPath), New iText.Kernel.Pdf.PdfWriter(tempFile))
|
||||
|
||||
|
||||
|
||||
Dim xmlBytes = File.ReadAllBytes(xmlPath)
|
||||
Dim fileName As String = "factur-x.xml"
|
||||
|
||||
If HasAttachment(pdf, fileName) Then
|
||||
Return pdfPath
|
||||
End If
|
||||
|
||||
Dim fs = PdfFileSpec.CreateEmbeddedFileSpec(
|
||||
pdf,
|
||||
xmlBytes,
|
||||
@@ -2490,6 +2496,32 @@ Public Class DATENVERVER_OPTIONS
|
||||
|
||||
End Function
|
||||
|
||||
Private Shared Function HasAttachment(pdf As iText.Kernel.Pdf.PdfDocument, fileName As String) As Boolean
|
||||
|
||||
Dim catalog = pdf.GetCatalog().GetPdfObject()
|
||||
Dim afObj = catalog.Get(iText.Kernel.Pdf.PdfName.AF)
|
||||
|
||||
If afObj Is Nothing Then Return False
|
||||
|
||||
Dim afArray = TryCast(afObj, iText.Kernel.Pdf.PdfArray)
|
||||
If afArray Is Nothing Then Return False
|
||||
|
||||
For i As Integer = 0 To afArray.Size() - 1
|
||||
Dim fsObj = afArray.Get(i)
|
||||
Dim fsDict = TryCast(fsObj, iText.Kernel.Pdf.PdfDictionary)
|
||||
|
||||
If fsDict Is Nothing Then Continue For
|
||||
|
||||
Dim fName = fsDict.GetAsString(iText.Kernel.Pdf.PdfName.F)
|
||||
|
||||
If fName IsNot Nothing AndAlso fName.ToString().Equals(fileName, StringComparison.OrdinalIgnoreCase) Then
|
||||
Return True
|
||||
End If
|
||||
Next
|
||||
|
||||
Return False
|
||||
End Function
|
||||
|
||||
|
||||
Public Shared Function ConvertToPdfA3(inputPdf As String) As String
|
||||
|
||||
|
||||
Reference in New Issue
Block a user