pdf merge

This commit is contained in:
2025-01-02 09:52:01 +01:00
parent ed70c04464
commit ea99771b7c

View File

@@ -8,6 +8,9 @@ Imports System.Reflection
Imports System.Text.RegularExpressions Imports System.Text.RegularExpressions
Imports System.Windows.Documents Imports System.Windows.Documents
Imports VERAG_PROG_ALLGEMEIN Imports VERAG_PROG_ALLGEMEIN
Imports com.sun.tools.internal.ws.wsdl.document.mime
Imports com.sun.xml.internal.ws.message.stream
Public Class frmFormulare Public Class frmFormulare
Dim isSingleForm = False Dim isSingleForm = False
Event ShownFIN() Event ShownFIN()
@@ -6527,8 +6530,11 @@ Public Class FormularManagerNEU
If file.ToUpper.EndsWith(".PDF") Then If file.ToUpper.EndsWith(".PDF") Then
reader = New PdfReader(file) reader = New PdfReader(file)
addAttachmentToCurrentPDF(reader, pdf)
pdf.AddDocument(reader) pdf.AddDocument(reader)
reader.Close() reader.Close()
End If End If
Next Next
Catch __unusedException1__ As Exception Catch __unusedException1__ As Exception
@@ -6549,6 +6555,41 @@ Public Class FormularManagerNEU
Return merged Return merged
End Function End Function
Public Shared Function addAttachmentToCurrentPDF(reader As PdfReader, copy As PdfCopy)
Dim catalog As PdfDictionary = reader.Catalog
Dim names As PdfDictionary = CType(PdfReader.GetPdfObject(catalog.Get(PdfName.NAMES)), PdfDictionary)
If names IsNot Nothing Then
Dim embeddedFiles As PdfDictionary = CType(PdfReader.GetPdfObject(names.Get(PdfName.EMBEDDEDFILES)), PdfDictionary)
If embeddedFiles IsNot Nothing Then
Dim filespecs As PdfArray = embeddedFiles.GetAsArray(PdfName.NAMES)
For i As Integer = 0 To filespecs.Size - 1 Step 2
' Get the attachment's file specification
Dim fileArray As PdfDictionary = filespecs.GetAsDict(i + 1)
Dim file As PdfDictionary = fileArray.GetAsDict(PdfName.EF)
For Each key As PdfName In file.Keys
Dim stream As PRStream = CType(PdfReader.GetPdfObject(file.GetAsIndirectObject(key)), PRStream)
Dim fileName As String = fileArray.GetAsString(key).ToString()
' Create a byte array from the attachment content
Dim fileContent As Byte() = PdfReader.GetStreamBytes(stream)
' Add the attachment to the new PDF
Dim fileSpec As PdfFileSpecification = PdfFileSpecification.FileEmbedded(copy, Nothing, fileName, fileContent)
copy.AddFileAttachment(fileName, fileSpec)
Next
Next
End If
End If
End Function
'ALT: Hier kam es zum komischen Problemen bei einem PDF: es wurde eine alte Verison ausgegeben, obwohl die alten texte nicht ersichtlich waren?? --> Infoschreiben Fiskal 'ALT: Hier kam es zum komischen Problemen bei einem PDF: es wurde eine alte Verison ausgegeben, obwohl die alten texte nicht ersichtlich waren?? --> Infoschreiben Fiskal
Public Shared Function MergePdfFiles2ALT(ByVal pdfFiles As List(Of String), ByVal outputPath As String) As Boolean Public Shared Function MergePdfFiles2ALT(ByVal pdfFiles As List(Of String), ByVal outputPath As String) As Boolean
Dim result As Boolean = False Dim result As Boolean = False