Bookmarks

Working with Bookmarks

For most use cases, you do not need to interact with the bookmarks model yourself, as PSPDFKit provides a UI for users to add, remove, and sort bookmarks depending on the configuration in use. It then automatically stores them in the PDF document they belong to. However, when you want to provide either your own UI or your own bookmarks store, you need to access the model that PSPDFKit provides for you.

The bookmarks model essentially consists of two classes: Bookmark, which is the bookmark itself and contains information about its name and what to do if a user selects a bookmark; and BookmarkProvider, which is the container that keeps track of all the bookmarks of a document. You can access the bookmark provider through PdfDocument#getBookmarkProvider(). This can then be used to retrieve, sort, add, and remove bookmarks.

Accessing Bookmarks

To access bookmarks, you can use getBookmarks() or getBookmarksAsync(). This will give you a list of all bookmarks sorted correctly.

Adding and Removing Bookmarks

To add bookmarks, simply call addBookmark() or addBookmarkAsync() on the bookmark provider, passing in the bookmark that you want to add to the bookmark provider. If you instead want to remove a bookmark, call removeBookmark() or removeBookmarkAsync(). If you want these changes to be stored, you need to save the associated document, which in turn will make sure the bookmark provider saves its content. By default, PSPDFKit automatically saves changes to a document at specific points.

Updating Bookmarks

If you want to make changes to a bookmark, you can just modify the object you received by calling getBookmarks(). Any changes you make will automatically be synced to the bookmark provider.