PDF Navigation
Page Navigation
After loading a PDF document, you can programmatically interact with it, which allows you to scroll to different pages or destinations. All of the interaction APIs are available on CPDFReaderView
, which is the core PDF viewer.
Scrolls to the specified page, use function CPDFReaderView.setDisplayPageIndex(pageIndex)
.
Outline
The outline allows users to quickly locate and link their points of interest within a PDF document. Each outline contains a destination or actions to describe where it links to. It is a tree-structured hierarchy, so function CPDFDocument.getOutlineRoot()
must be called first to get the root of the whole outline tree before accessing the outline tree. Here, “root outline” is an abstract object which can only have some child outline without the next sibling outline and any data (includes outline data, destination data, and action data). It cannot be shown on the application UI since it has no data. You can also use function CPDFDocument.newOutlineRoot()
to create a new root outline.
After the root outline is retrieved, the following functions can be called to access other outlines:
- To access the parent outline, use function CPDFOutline.getParent()
.
- To access the child outline.
public ArrayList childOutline() {
CPDFOutline pdfOutlineRoot = document.getOutlineRoot();
CPDFOutline[] outlines = pdfOutlineRoot.getChildList();
ArrayList outlineList = new ArrayList<>();
int numberOfOutline = outlines.length;
for (int i = 0; i < numberOfOutline; i++) {
outlineList.add(outlines[i]);
}
return outlineList;
}
- To insert a new outline, use function CPDFOutline.insertChildAtIndex(index)
.
- To remove an outline, use function CPDFOutline.removeFromParent()
.
- To move an outline, use function CPDFOutline.insertChildAtIndex(index)
. When moving items around within an outline hierarchy, you should retain the item and call CPDFOutline.removeFromParent()
first.
Bookmarks
Since each bookmark is associated with a specific page, it provides the ability to link to a different page in a document allowing the user to navigate interactively from one part of the document to another.
- To access bookmarks, use function CPDFDocument.getBookmarks
.
- To access a bookmark for page, use function CPDFDocument.hasBookmark(pageIndex)
.
- To add a new bookmark, use function CPDFDocument.addBookmark(CPDFBookmark)
.
- To remove a bookmark, use function CPDFDocument.removeBookmark(pageIndex)
.