We are currently in the process of changing the PDF toolkit that we use in our Excel VBA Application. We are actually controlling pdfTK using command line batch script to be able to merge documents together.
I've installed Core API SDK and started coding some test code to get the hang of it. I've reused code I've found on this forum but now I'm stuck on combining documents together.
I'd like to use a mergePDF function that takes 2 parameters to work: sMainDocPath for the main document that we would like to add pages at the end and the arrayFilesPath array that should hold all the files path that needs to be added. This function should send back the output file path if the operation was successful.
Here is how it's coded so far:
Code: Select all
Public Sub DocCombine()
Dim ary(1) As Variant
Dim sMainDoc As String
'main document that we want to merge other pdf at the end
sMainDoc = Environ("TEMP") & "\2021_01_20_CPAP_212857_Rapport suivi Stickies.pdf"
'build array with all the files we want to combine at the end of main doc
ary(0) = Environ("TEMP") & "\Annexe 1 Effluent Bury X rays.pdf"
ary(1) = Environ("TEMP") & "\Test B.pdf"
'call the mergePDF
Call mergePDF(sMainDoc, ary)
End Sub
Code: Select all
Private Function mergePDF(sMainDocPath As String, arrayFilesPath() As Variant) As String
Dim objPXC As New PDFXCoreAPI.PXC_Inst
Dim objDcb As IPXC_DocAuthCallback
Dim objDocMain As IPXC_Document
Dim objDocExtra As IPXC_Document
Dim objContent As IPXC_Content
objPXC.Init ""
Set objDoc = objPXC.OpenDocumentFromFile(Environ("TEMP") & "\2021_01_20_CPAP_212857_Rapport suivi Stickies.pdf", objDcb)
For i = lbound(arrayFilesPath) to ubound(arrayFilesPath)
'the following is non-sense, Im just trying to code what I want to do
objDoc.addPages(arrayFilesPath(i))
next
objdoc.writeToFile Environ("Temp") & "\test.pdf"
objdoc.close
objPXC.Finalize
Set objDoc = nothing
Set objPXC = nothing
End Function
Thanks!