Table of Contents
Creating Bookmarks

Overview

A PDF document may optionally include a bookmark tree allowing the user to navigate interactively from one part of the document to another. The bookmark tree consists of a tree-structured hierarchy of bookmarks.

Creating Top Level Bookmark

Follow these steps to create a top level bookmark:

  1. Create a PdfBookmark object:

    //Create a PdfBookmark object with text "Chapter 1"            
    PdfBookmark bookmark = new PdfBookmark("Chapter 1");
  2. Set the bookmark's Destination property to a PdfDestination object. The easiest way to create a PdfDestination object is to call AcmContent's CreateDestination to create a PdfDestination object that represents the top position of the content. Note that you can only call this function after the content has been rendered.

    //Initializes the bookmark's Destination property            
    bookmark.Destination = content.CreateDestination();
  3. Add the bookmark to the document's catalog:

    //Add it as a top level bookmark, "doc"
    //is a PdfDocument object
    doc.Bookmarks.Add(bookmark);

Creating Child Bookmark

Creating a child bookmark is the same as creating a top level bookmark, except that instead of adding the bookmark into the document's catalog, the new bookmark is added to its parent bookmark's ChildNodes collection:

//Create a child bookmark under "parentBookmark"
parentBookmark.ChildNodes.Add(childBookmark);