Foxit PDF SDK for Windows

How to Add Bookmarks with Foxit PDF SDK (C++)

Bookmark

Foxit PDF SDK provides navigational tools called Bookmarks to allow users to quickly locate and link their point of interest within a PDF document. PDF bookmarks are also called outline, and each bookmark contains a destination or actions to describe where it links to. The hierarchy is tree-structured. This means that function pdf.PDFDoc.GetRootBookmark must be called first to get the root of the whole bookmark tree. Here, “root bookmark” is an abstract object which can only have some child bookmarks without sibling bookmarks and any data (including bookmark data, destination data and action data). It cannot be shown on the application UI since it has no data. Therefore, a root bookmark can only call the function Bookmark.GetFirstChild.

After the root bookmark is retrieved, the following functions can be called to access other bookmarks:

  • To access the parent bookmark, use function Bookmark.GetParent.
  • To access the first child bookmark, use function Bookmark.GetFirstChild.
  • To access the next sibling bookmark, use function Bookmark.GetNextSibling.
  • To insert a new bookmark, use function Bookmark.Insert.
  • To move a bookmark, use function Bookmark.MoveTo.

Example:

How to find and list all bookmarks of a PDF

using foxit;
using foxit.common;
using foxit.common.fxcrt;
using foxit.pdf;
using foxit.pdf.actions;
...
//Assuming PDFDoc doc has been loaded.
...
Bookmark root = doc.GetRootBookmark();
Bookmark first_bookmark = root.GetFirstChild();
if (first_bookmark != null)
{
TraverseBookmark(first_bookmark, 0);
}
Private void TraverseBookmark(Bookmark root, int iLevel)
{
if (root != null)
{
 Bookmark child = root.GetFirstChild();
 while (child != null)
 {
 TraverseBookmark(child, iLevel + 1);
 child = child.GetNextSibling();
 }
 }
}
...

Updated on April 28, 2019

Was this article helpful?
Thanks for your feedback. If you have a comment on how to improve the article, you can write it here: