- insert a bookmark with the original PDF filename as the bookmark title (ie. 3 bookings : doc1, doc2, doc3 in doc_merged)
- add some basic headers and footers
For bookmarks, I found the documentation incomplete (though nice and concise), and the support responses poor. Headers were fine.
I've posted my solution here in case others need to do the same:
Code: Select all
'
' Use PDF Tracker API to combine a list of PDF files into a single file
' fullfilenames: array of PDF files
' fullpath: name of file to write merged PDFs to (will be overwritten)
'
Function CombinePDFS_PDFXChange(fullfilenames As Collection, fullpath As String)
Dim PDFPrinter As PXCComLib5.CPXCPrinter
Dim PDFPFactory As New PXCComLib5.CPXCControlEx
Dim fullfilename
Dim filename As String
Const debuga = True
' Overwrite existing
On Error Resume Next
Kill fullpath & ".pdf"
On Error GoTo 0
' Load up the Tracker API
Set PDFPrinter = PDFPFactory.printer("", "PDF-XChange", "PDS50-FLZFR-BHUUE-IGT90-V9LZ0-2IH88", "PDFX3$Henry$300604_Allnuts#")
With PDFPrinter
.SetAsDefaultPrinter
.ResetDefaults
.Option("DocInfo.Enabled") = True ' MUST set this to make bookmark as doctitle work (not documented)
.Option("Bookmarks.Enabled") = True
.Option("Bookmarks.DocTitleAsRoot") = True ' MUST set this to make bookmark as doctitle work
.Option("Save.File") = fullpath
.Option("Save.SaveType") = "Save"
.Option("Save.ShowSaveDialog") = "No"
.Option("Save.WhenExists") = "Append" ' To create a merged file, append one after the other
.Option("Save.RunApp") = False
.Option("Saver.ShowProgress") = "Yes"
.Option("HeadersFooters.Enabled") = True
.Option("HeadersFooters.Header.Right.FontSize") = 8 * 10
.Option("HeadersFooters.Header.Right.Color") = RGB(255, 0, 0)
.Option("HeadersFooters.Header.Left.FontSize") = 8 * 10
.Option("HeadersFooters.Header.Left.Color") = RGB(255, 0, 0)
.Option("HeadersFooters.OffsetTop") = 5 * 10
.Option("HeadersFooters.OffsetRight") = 5 * 10
.Option("HeadersFooters.OffsetLeft") = 5 * 10
.Option("HeadersFooters.Header.Left.Value") = "Green Star Sub-Document Page: %[Page] of %[Pages] "
.Option("HeadersFooters.Header.Right.Value") = "Green Star Document: %[DocName]"
End With
Call PDFPrinter.ApplyOptions(0) ' MUST call this to apply options
' Loop through each file, printing and appending to merged file
For Each fullfilename In fullfilenames
' Set the document title to help bookmarks work
Call SplitPath(fullfilename, , , , filename)
PDFPrinter.Option("DocInfo.Title") = filename ' MUST set this to make bookmark as doctitle work (not documented)
Call PDFPrinter.ApplyOptions(0)
' Print it
Call ShellExecute(0, "printto", fullfilename, """" + PDFPrinter.Name + """", vbNull, 0) ' Really should check return value
' Wait until printing it is finished
DoEvents
Sleep (500)
While (PDFPrinter.LastPrintEvent() <> event_DocumentSaved)
DoEvents
Sleep (500)
Wend
Next
End Function