
Adobe Acrobat SDK
Working with Bookmarks
Developing Plug-ins and Applications
Retrieving bookmarks 118
Retrieving bookmarks
You can use the Acrobat core API to retrieve bookmarks located within a PDF document. You can retrieve
the root bookmark, retrieve a specific bookmark, or retrieve all bookmarks that are located within a PDF
document.
Retrieving the root bookmark
Every PDF document has a root bookmark. The root bookmark does not represent a physical bookmark,
but is the root from which all bookmarks in the tree are descended.
The following code example shows how to get a PDF document’s root bookmark by creating application
logic within a user-defined function named
GetFirstBookmark
. First, the
PDDocGetBookmarkRoot
method is invoked to get the bookmark root. This method requires a
PDDoc
object that represents the
PDF document from which the root bookmark is retrieved and returns a
PDBookmark
object that
represents the root bookmark. For information, see
“Creating a PDDoc object” on page 83
.
Next, the
PDBookmarkGetFirstChild
method is invoked to get the first child of the root. If there are no
bookmarks,
PDBookmarkGetFirstChild
returns
NULL
.
Example 9.4
Retrieving the root bookmark
PDBookmark GetFirstBookmark(PDDoc doc)
{
PDBookmark theroot, childBookmark;
theroot = PDDocGetBookmarkRoot(doc);
childBookmark = PDBookmarkGetFirstChild(theroot);
return childBookmark;
}
Retrieving a specific bookmark
You can retrieve a specific bookmark by specifying its title. The following code example retrieves a specific
bookmark by invoking the
PDDocGetBookmarkRoot
method to get the document’s root bookmark as a
starting point for the search. It then invokes the
PDBookmarkGetByTitle
method to retrieve the first
bookmark whose title matches the specified title. This method requires the following arguments:
●
The root of the bookmark tree that is searched.
●
A character pointer that specifies the title of the bookmark.
●
An
ASInt32
object that specifies the length of the character pointer.
●
An
ASInt32
object that specifies the number of bookmark levels to search. The value
-1
specifies to
search the entire sub-tree. The value
1
specifies to search only child bookmarks of the current
bookmark. The value
0
specifies to look at the current bookmark.
Example 9.5
Retrieving a specific bookmark
//Retrieve a bookmark whose title is Samples
PDBookmark rootBookmark, myBookmark;
char* bookmarkTitle = "Samples";
//Get the root bookmark
rootBookmark = PDDocGetBookmarkRoot(myPDDoc);