Some test text!

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.

While it's possible to work with outline items using the SDF API (See section 8.2.2, "Document Outline", in the PDF Reference Manual for more details), PDFTron SDK simplifies the process by providing the high-level utility class PDF.Bookmark.

You can use Bookmark.GetNext(), Bookmark.GetPrev(), Bookmark.GetFirstChild() and Bookmark.GetLastChild() to navigate the whole outline tree, as the following shows:

// Prints out the outline tree to the standard output

void PrintIdent(Bookmark item)
  int ident = item.GetIdent() - 1;
  for (int i=0; i < ident; ++i)
  Console.Write("  ");

void PrintOutlineTree(Bookmark item)
  for (; item.IsValid(); item=item.GetNext())
      (item.IsOpen() ? "- " : "+ "), item.GetTitle());
    if (item.HasChildren())     
      // Recursively print child subtrees

static void Main(string[] args)
  PDFDoc doc = new PDFDoc("../../../Data/out1.pdf");

  Bookmark root = doc.GetFirstBookmark();

Note that we obtain the root Bookmark using GetFirstBookmark(). If GetFirstBookmark() returns an invalid Bookmark (where GetFirstBookmark().IsValid() is false), the document has no outline tree. A new outline three can be created as follows:

PDFDoc doc = new PDFDoc("../Data/in.pdf");

Bookmark myitem = Bookmark.Create(doc, "My Item");

Sub-items can be added using the Bookmark.AddChild() method:

Bookmark sub_item = myitem.AddChild("My Sub-Item");
myitem.AddChild("My Sub-Item 2");

Note that a Bookmark can be associated with different kinds of Actions. The most common action is to move to another location in the current document. This type of Action is called a Go-To action. The following sample creates a new page Destination and sets the Bookmark's action:

// The following example creates an 'explicit' destination
Destination dest = Destination.CreateFit(doc.GetPage(1));
Action action = Action.CreateGoto(dest);

Using PDFTron SDK, it is also possible to quickly create named destinations. Named destinations have an advantage over explicit destinations — they allow the location of the destination to change without invalidating existing links.

To create a named destination, pass the key (under which the destination will be stored) to the Action.Create() method:

Action blue_action
  = Action.CreateGoto(

The Bookmarks class also allows you to quickly find Bookmarks based on the title text. For example, the following code snippet looks for a Bookmark called foo and then removes it from the outline tree:

Bookmark foo = doc.GetFirstBookmark().Find("foo");
if (foo.IsValid())

The Bookmark API allows you to change any property on an outline item, including title text, action, color, and formatting. Color and other formatting can help readers navigate large PDF documents more easily. The following code adjusts color and formatting properties on three Bookmark items:

red.SetColor(1, 0, 0);
green.SetColor(0, 1, 0);

// use bold font for green title text
blue.SetColor(0, 0, 1);

// use bold and italic font for blue title text

Get the answers you need: Support