Bookmark Navigation in Our JavaScript PDF Viewer

PSPDFKit for Web’s UI features a sidebar with different available views.

The bookmarks sidebar shows a list of bookmarks available in a document, which are grouped and ordered by page. The sidebar can be used to navigate to the bookmarked pages.

Sidebar.

The bookmarks sidebar can be shown by the user by selecting the bookmarks sidebar icon from the sidebar dropdown in the toolbar.

It can also be shown programmatically with the API:

instance.setViewState(viewState => viewState.set("sidebarMode", PSPDFKit.SidebarMode.BOOKMARKS);

Additionally, it’s possible to make it appear when the document is loaded by setting PSPDFKit.Configuration#initialViewState:

PSPDFKit.load({
  initialViewState: new PSPDFKit.ViewState({
    sidebarMode: PSPDFKit.SidebarMode.BOOKMARKS
  })
});

The sidebar, which appears to the left of the viewport by default, can also be configured to appear to the right. To do this, you only need to set PSPDFKit.ViewState#sidebarPlacement:

instance.setViewState(viewState => (
  viewState.set("sidebarPlacement", PSPDFKit.SidebarPlacement.END)
));

The image below shows how sidebar looks once placed using the previous snippet.

Sidebar placed on the right side.

If you don’t want users to be able to open the bookmarks sidebar, you can hide the corresponding toolbar button by filtering it out from the default toolbar items:

PSPDFKit.setToolbarItems(items => items.filter(item => item.type !== "sidebar-bookmarks"));

The bookmarks sidebar toolbar button can be styled with CSS using the public CSS class .PSPDFKit-Toolbar-Button-Sidebar-Bookmarks.

The bookmarks sidebar itself can also be customized with CSS by modifying the corresponding public CSS classes: