1. Home
  2. Foxit PDF SDK for Windows
  3. How to Add Bookmarks with Foxit PDF SDK (Java)
  1. Home
  2. Foxit PDF SDK for Mac
  3. How to Add Bookmarks with Foxit PDF SDK (Java)
  1. Home
  2. Foxit PDF SDK for Linux
  3. How to Add Bookmarks with Foxit PDF SDK (Java)

How to Add Bookmarks with Foxit PDF SDK (Java)

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

import com.foxit.sdk.pdf.Bookmark;
import com.foxit.sdk.pdf.PDFDoc;
...
// Assuming PDFDoc doc has been loaded.
...
Bookmark root = doc.getRootBookmark();
if (root.isEmpty()) {
root = doc.createRootBookmark();
}
String titleStr = "";
Bookmark iterBookmark = root.getFirstChild ();
if (iterBookmark.isEmpty())
return;
while (!iterBookmark.isEmpty())
{
titleStr = iterBookmark.getTitle();
if (iterBookmark.hasChild())
{
Bookmark childBookmark = iterBookmark.getFirstChild();
titleStr = childBookmark.getTitle();
}
iterBookmark = iterBookmark.getNextSibling();
}
...
Updated on November 13, 2019

Was this article helpful?

Related Articles