I just found the solution.
If there is
only one document, maintain the property values in the source (word, excel, PowerPoint, ... )
produce the pdf with:
Code: Select all
'If it is a Word document
If Not DOC Is Nothing Then
With DOC
.ExportAsFixedFormat PDFOutputFilename, 17, False, 0, , , , , True, , , , True, False
End With
End If
'If it is an Excel document
If Not SHT Is Nothing Then
With SHT
.ExportAsFixedFormat xlTypePDF, PDFOutputFilename, , True, , , , False
End With
End If
If you have to
merge several pdf files and take care, there is in the final document the correct property title, you must set the values in the first file of the merged files.
Instead of open the
Set objDocMain = objPXC.NewDocument() take the
first document of the list as
objDocMain.
I hope it helps...
Best regards
Roland
Code: Select all
Public Function testPDF(strInput As String)
On Error GoTo testPDF_error
' execute in direct window:
' (replace files with your pdf files)
'testPDF "W:\your path to file\FileOne.pdf#" _
& "W:\your path to file\FileTwo.pdf#" _
& "W:\your path to file\FileThree.pdf#" _
& "W:\your path to file\FileFour.pdf"
Dim objDocMain As IPXC_Document ' holder for the main document
Dim objDocSlaves As IPXC_Document ' add the additional pages
Dim i As Long ' counter for page add loop
Dim bolObjPxcDone As Boolean ' check for objPXC license object
Dim arrayFilesPath() As String
arrayFilesPath = Split(strInput, "#")
'/// first page as main:
' set objPXC flag to false - error 91 missing object can be for other objects as well...
bolObjPxcDone = False
'Create Main Doc for first page - his must contain all properties like title, author, etc
Set objDocMain = objPXC.OpenDocumentFromFile(arrayFilesPath(0), Nothing)
' set objPXC flag to true again.
bolObjPxcDone = True
'/// catch second document
Set objDocSlaves = objPXC.OpenDocumentFromFile(arrayFilesPath(1), Nothing)
'add it to final document
objDocMain.Pages.InsertPagesFromDoc objDocSlaves, objDocMain.Pages.Count, 0, objDocSlaves.Pages.Count, 0
'Empty variable
Set objDocSlaves = Nothing
'/// Loop all remaining files path and add pages at the end of MAIN doc
If UBound(arrayFilesPath) > 1 Then
For i = 2 To UBound(arrayFilesPath)
If arrayFilesPath(i) <> "" Then
'catch a document
Set objDocSlaves = objPXC.OpenDocumentFromFile(arrayFilesPath(i), Nothing)
'add it to final document
objDocMain.Pages.InsertPagesFromDoc objDocSlaves, objDocMain.Pages.Count, 0, objDocSlaves.Pages.Count, 0
'Empty variable at each loop
Set objDocSlaves = Nothing
End If
Next i
Else
' only 2 pages... no further action
End If
MainDocComplete:
'Write final file
objDocMain.WriteToFile "W:\L\BDTP\Products\FSA_EquityAdvisory\Output\Test\sirtTest.pdf"
objDocMain.Close
testPDF_exit:
Exit Function
testPDF_error:
Select Case Err.Number
Case -2080440318 ' Automation error
' looks like a file is not available. take next file
If i = UBound(arrayFilesPath) Then
Set objDocSlaves = Nothing ' close object and jump out of the loop
GoTo MainDocComplete
Else
i = i + 1 ' take next file
Resume
End If
Case 91 ' Object variable or With block variable not set
If bolObjPxcDone = False Then
initiatePdfXchange
Resume
End If
Case Else
Debug.Print Err.Number; "' "; Err.Description
Stop
Resume
End Select
End Function
Public Function initiatePdfXchange()
Dim objFSO As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objTF As Object
' replace the file with your license file
Set objTF = objFSO.OpenTextFile("\\your path to file\pdfXchange_license.txt", 1)
Dim apiKey As String
apiKey = objTF.readall
'initialization
Set objPXC = New PDFXCoreAPI.PXC_Inst
objPXC.Init sKey:=apiKey
End Function