Foxit PDF SDK for iOS

How to Apply and Manage Bookmarks with Foxit PDF SDK for iOS

Bookmark (Outline)

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 bookmark is also called outline, and each bookmark contains a destination or actions to describe where it links to. It is a tree-structured hierarchy, so function FSPDFDoc::getRootBookmark must be called first to get the root of the whole bookmark tree before accessing the bookmark tree. Here, “root bookmark” is an abstract object which can only have child bookmarks without next sibling bookmarks and 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 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 go through a PDF’s bookmarks in ascending order

#import "ViewController.h"
#import 
...
- (void)DepthFistTravelBookmarkTree: (FSBookmark*)bookmark  document: (FSPDFDoc*)doc {
    if(!bookmark || [bookmark isEmpty])
        return;
    [self DepthFistTravelBookmarkTree:[bookmark getFirstChild] document:doc];
    while(true) {
        // Get bookmark title.
        NSString* title = [bookmark getTitle];
        FSDestination* dest = [bookmark getDestination];
        if(dest && ![dest isEmpty])
        {
            float left,right,top,bottom;
            float zoom;
            int pageIndex = [dest getPageIndex:doc];
            // left, right, top, bottom, zoom are only meaningful with some special zoom modes.
            FSDestinationZoomMode mode = [dest getZoomMode];
            switch (mode) {
                case FSDestinationZoomXYZ:
                    left = [dest getLeft];
                    top = [dest getTop];
                    zoom = [dest getZoomFactor];
                    break;
                case FSDestinationZoomFitPage:
                    break;
                case FSDestinationZoomFitHorz:
                    top = [dest getTop];
                    break;
                case FSDestinationZoomFitVert:
                    left = [dest getLeft];
                    break;
                case FSDestinationZoomFitRect:
                    left = [dest getLeft];
                    bottom = [dest getBottom];
                    right = [dest getRight];
                    top = [dest getTop];
                    break;
                case FSDestinationZoomFitBBox:
                    break;
                case FSDestinationZoomFitBHorz:
                    top = [dest getTop];
                    break;
                case FSDestinationZoomFitBVert:
                    left = [dest getLeft];
                    break;
                default:
                    break;
            }
        }
        bookmark = [bookmark getNextSibling];
        if(bookmark == nil || [bookmark isEmpty])
            break;
        [self DepthFistTravelBookmarkTree:[bookmark getFirstChild] document:doc];
    }
}

Reading Bookmark

A reading bookmark is not a PDF bookmark. In other words, it does not have PDF outlines. It is the bookmark for an applicable level. It is stored in the metadata (XML format) of the catalog. It allows user to add or remove a reading bookmark according to their reading preferences and navigate one PDF page easily by selecting a reading bookmark.

In order to retrieve the reading bookmark, function PDFDoc.getReadingBookmarkCount could be called to count the reading bookmarks, and function PDFDoc.getReadingBookmark could be called to get a reading bookmark by index.

This class offers several functions to get/set properties of reading bookmarks, such as title, destination page index and creation/modified date time.

How to add a custom reading bookmark and enumerate all reading bookmarks

#import "ViewController.h"
#import 
...
// Add a new reading bookmark to pdf document, the returned bookmark stores the title and the page index.
- (FSReadingBookmark*)addReadingBookmark: (FSPDFDoc*)pdfDoc title: (NSString*)title pageIndex: (int)pageIndex {
    int count = [pdfDoc getReadingBookmarkCount];
    return [pdfDoc insertReadingBookmark:count title:title dest_page_index:pageIndex];
}
// Enumerate all the reading bookmarks from the pdf document.
- (void)getReadingBookmark: (FSPDFDoc*) pdfDoc {
    int count = [pdfDoc getReadingBookmarkCount];
    for(int i=0; iif([bm isEmpty]) continue;
        // Get bookmark title.
        NSString* title = [bm getTitle];
        // Get the page index which associated with the bookmark.
        int pageIndex = [bm getPageIndex];
        // Get the creation date of the bookmark.
        FSDateTime* creationDate = [bm getDateTime:YES];
        // Get the modification date of the bookmark.
        FSDateTime* modificationDate = [bm getDateTime:NO];
    }
}

Updated on July 21, 2021

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