Adding bookmarks - one for each sub-document in merged file

PDF-XChange Drivers API (only) V4/V5
This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-XChange Printer Drivers SDK (only) - VERSION 4 & 5 - Please use the PDF-Tools SDK Forum for Library DLL assistance.

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Chris - Tracker Supp, Tracker Supp-Stefan

Post Reply
lehr consultants international
Posts: 1
Joined: Thu Sep 20, 2012 12:21 am

Adding bookmarks - one for each sub-document in merged file

Post by lehr consultants international » Tue Sep 25, 2012 1:15 am

I needed to merge PDF documents (eg. doc1, doc2, doc3) into a one pdf (eg. doc_merged) and
- 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
        .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
        Sleep (500)
        While (PDFPrinter.LastPrintEvent() <> event_DocumentSaved)
            Sleep (500)
End Function
(I hope this is the right place for this.)

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13663
Joined: Mon Jan 12, 2009 8:07 am
Location: London

Re: Adding bookmarks - one for each sub-document in merged f

Post by Tracker Supp-Stefan » Tue Sep 25, 2012 9:17 am

Hi Brett,

And thank you for sharing your solution!
I am sorry I could not find this one out for you. :(

The correct forum is the drivers API one - so I've already moved the topic there.


Post Reply