How to Add Bookmarks with Foxit PDF SDK (Objective-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 FSPDFDoc::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 FSBookmark::getFirstChild.
After the root bookmark is retrieved, the following functions can be called to access other bookmarks:
- To access the parent bookmark, use function FSBookmark::getParent.
- To access the first child bookmark, use function FSBookmark::getFirstChild.
- To access the next sibling bookmark, use function FSBookmark::getNextSibling.
- To insert a new bookmark, use function FSBookmark::insert.
- To move a bookmark, use function FSBookmark::moveTo.
Example:
How to find and list all bookmarks of a PDF
#include "FSPDFObjC.h" ... // Assuming FSPDFDoc doc has been loaded. ... FSBookmark *root = [doc getRootBookmark]; if (![root isEmpty]) { ShowBookmarkInfo(root, info, 0); } void ShowBookmarkInfo(FSBookmark *bookmark, int depth) { if (depth > 32) return; if ([bookmark isEmpty]) { return; } ShowBookmarkInfo([bookmark getFirstChild], depth + 1); ShowBookmarkInfo([bookmark getNextSibling], depth); } ...
Updated on April 28, 2019