Navigate PDF outline tree on Server/Desktop

The basic code needed to navigate an outline tree and print its result:

1function PrintIndent ($item) {
2 $ident = $item->GetIndent() - 1;
3 for ($i=0; $i<$ident; ++$i) {
4 echo " ";
5 }
6}
7function PrintOutlineTree($item) {
8 for (; $item->IsValid(); $item=$item->GetNext()) {
9 PrintIndent($item);
10 echo ($item->IsOpen() ? "- " : "+ ").$item->GetTitle()." ACTION -> ";
11 if ($item->HasChildren()) {
12 PrintOutlineTree($item->GetFirstChild());
13 }
14 }
15}
16$doc = new PDFDoc($filename);
17$root = $doc->GetFirstBookmark();
18PrintOutlineTree($root);

Read, add, edit PDF outlines and bookmarks - Full Sample
Full code sample which illustrates how to read and edit existing outline items and create new bookmarks using the high-level API. Samples available in Python, C# (.Net), C++, Go, Java, Node.js (JavaScript), PHP, Ruby, VB. To use this code, you'll need to download and get started with Server SDK.

About outline tree

A PDF document may display a document outline on the screen, allowing the user to navigate interactively from one part of the document to another. The outline consists of a tree-structured hierarchy of Bookmarks (sometimes called outline items), which serve as a "visual table of contents" to display the document's structure to the user.

Each Bookmark has a title that appears on screen, and an Action that specifies what happens when a user clicks on the Bookmark. The typical Action for a user-created Bookmark is to move to another location in the current document — although any Action can be specified.

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales