
Adobe Acrobat SDK
Working with Bookmarks
Developing Plug-ins and Applications
Creating bookmarks 114
The Acrobat core API contains methods that operate on bookmarks. Using these methods, you can
perform the following tasks:
●
Create new bookmarks
●
Get and set various attributes of a bookmark (such as its title or action or whether it is open)
●
Search for a bookmark
Creating bookmarks
You can use the Acrobat core API to create a new bookmark that appears in a PDF document. Before you
can create a bookmark, you must create a
PDDoc
object that represents the PDF document to which the
bookmark is added. For information, see
“Creating a PDDoc object” on page 83
.
To create bookmarks for a PDF document, perform the following tasks:
1. Get the root of the PDF document's bookmark tree by invoking the
PDDocGetBookmarkRoot
method.
This method requires a
PDDoc
object and returns a
PDBookmark
object that represents the document's
root bookmark. The document’s root bookmark does not appear in Adobe Reader or Acrobat.
2. Create another
PDBookmark
object that represents the bookmark to add to the document’s root
bookmark by invoking the
PDBookmarkAddNewChild
method. This method requires a
PDBookmark
object that represents the parent bookmark (in this case the parent bookmark is also the document’s
root bookmark) and an
ASAtom
object that represents the bookmark’s title.
3. Create a
PDBookmark
object that represents a sibling bookmark to the bookmark that was added to
the document’s root bookmark (the sibling bookmark is also a child of the document’s root bookmark).
You can perform this task by invoking the
PDBookmarkAddNewSibling
method. This method
requires a
PDBookmark
object that represents the new bookmark’s sibling bookmark and an
ASAtom
object that represents the bookmark’s title.
The following code example adds two new bookmarks to a PDF document. After each bookmark is created, the
PDBookmarkIsValid
method is invoked to determine whether the bookmark is valid. The name of the
PDDoc
object used in this code example is
myPDDoc
. For information, see
“Creating a PDDoc object” on page 83
.
Example 9.1
Creating bookmarks
//Declare a bookmark object
PDBookmark rootBookmark;
PDBookmark childBookmark ;
PDBookmark siblingBookmark;
//Get the root bookmark
rootBookmark = PDDocGetBookmarkRoot(myPDDoc);
if (PDBookmarkIsValid(rootBookmark)){
//Add a child bookmark to the root bookmark
childBookmark = PDBookmarkAddNewChild(rootBookmark, "Bookmark1");
if (PDBookmarkIsValid(childBookmark)){
//Add a sibling bookmark to the child bookmark
siblingBookmark = PDBookmarkAddNewSibling(childBookmark, "Bookmark2");
}
}