Skip to content
ComPDF
DemoSampleAPI ReferenceFAQ
New Release

Open-Source PDF SDK & AI Document Processing

Get the full self-hosted SDK and AI document processing on GitHub. One-click deploy to quickly build your document workflows.

Guides

Bookmarks

Bookmarks are manually added location markers that help you quickly navigate to specific positions in a document. Unlike outlines, bookmarks usually reflect personalized points of interest during reading and support operations such as creation, retrieval, and deletion.

Get the Bookmark List

This example shows how to get the bookmarks list:

java
List<CPDFBookmark> bookmarkList = document.getBookmarks();

Add a New Bookmark

The steps for adding a new bookmark are as follows:

  1. Create a bookmark object.
  2. Set bookmark properties.
  3. Add the bookmark to the document.

This example shows how to add a new bookmark:

java
// Page indexes are zero-based, so 4 refers to page 5.
int pageIndex = 4;
// Create a bookmark object and set its properties.
CPDFBookmark bookmark = new CPDFBookmark(pageIndex, "new bookmark", CPDFDate.toStandardDate(TTimeUtil.getCurrentDate()));
// Add the bookmark to the document.
document.addBookmark(bookmark);
kotlin
// Page indexes are zero-based, so 4 refers to page 5.
val pageIndex = 4
// Create a bookmark object and set its properties.
val bookmark = CPDFBookmark(
  pageIndex,
  "new bookmark",
  CPDFDate.toStandardDate(TTimeUtil.getCurrentDate())
)
// Add the bookmark to the document.
document.addBookmark(bookmark)

Delete a Bookmark

Delete the bookmark for a specified page index. Page indexes are zero-based.

This example shows how to delete a bookmark:

java
// Delete the bookmark for the first page.
document.removeBookmark(0);

Check Whether a Bookmark Exists

Determine whether a bookmark exists on the specified page index. Page indexes are zero-based.

java
boolean hasBookmark = document.hasBookmark(pageIndex);