Creating Outlines (Bookmarks) tree for PDF document in PDFDoc Scout library

Download the source code of this example (VBScript) here: pdfdocscout_outlines.zip 
Download the source code of this example (VB.NET) here: pdfdocscout_outlines_vb_net.zip 

This example demonstrates how to generate bookmarks tree in PDF document using PDFDoc Scout library

Generated PDF document (screenshot):

Sample EMF metafile with text, vector and raster images converted into PDF document using PDFDoc Scout library

or view generated PDF document online: pdfdocscout_Outlines.pdf

Source code:

Set PDFDoc = CreateObject("PDFDocScout.PDFDocument") ' create PDFDoc object
PDFDoc.InitLibrary "demo", "demo" ' initialize library

PDFDoc.OutputFileName = "Outlines.pdf" ' set output filename for PDF document
PDFDoc.AutoOpenGeneratedPDF = true ' automatically open generated PDF document in default PDF viewer application

PDFDoc.ViewerOptions_PageMode = 1 ' 1=pmUseOutlines so PDF document will be opened with visible outlines tree by default

PDFDoc.BeginDocument ' starts PDF document generation

' add root outline node
Set actGotoPage = PDFDoc.AddGoToPageAction(0, 0) ' page #0 and top offset = 0 for the very first outline
Set outlineRoot = PDFDoc.Outlines.AddChild (nothing, "PDFDoc Scout Demo", actGotoPage, 0)
outlineRoot.Expanded = true ' root outline is expanded by default

PDFDoc.Page.AddText "This is a main page for this demo", 100, 10, 0

For i = 1 to 10

PDFDoc.AddPage

' add text to a page
PDFDoc.Page.AddText "This is a page #" & CStr(i), 100, 10, 0

' create outline for this page
Set actGotoPage = PDFDoc.AddGoToPageAction(i, 0) ' i = page number, 0 is Y top offset
Set outlinePage = PDFDoc.Outlines.AddChild (outlineRoot, "Page " +Cstr(i), actGotoPage, 0)

' now we add 5 sub-topics on the same page and then create sub-outlines for each sub-topic
for j=1 to 5

' add text for sub-topic
PDFDoc.Page.AddText "Sub-topic #" & Cstr(J+1) & " on page #" & CStr(i), 100, 100 + j*50, 0

' add sub-outline for sub-topic
Set actGotoSubTopicOnPage = PDFDoc.AddGoToPageAction(i, 100 + j*50) ' i = page number, 100 + j*50 is Y top offset for sub-topic
Set outlineSubTopic = PDFDoc.Outlines.AddChild (outlinePage, "Sub-topic #" +Cstr(j), actGotoSubTopicOnPage, 0)

Next

Next

PDFDoc.EndDocument ' close pdf document generation

' disconnect from library
Set PDFDoc = Nothing

Download the source code of this example (VBScript) here: pdfdocscout_outlines.zip 
Download the source code of this example (VB.NET) here: pdfdocscout_outlines_vb_net.zip 

Filed in: PDFDoc Scout SDK

Tutorials: