Create Bookmarks in PDF Using JavaScript

With PSPDFKit, it’s possible to create bookmarks both using the sidebar UI and programmatically with JavaScript. This guide will focus on the programmatic creation of bookmarks.

Here’s how to create a bookmark in JavaScript:

const bookmark = new PSPDFKit.Bookmark({
  name: "test bookmark",
  action: new PSPDFKit.Actions.GoToAction({ pageIndex: 3 })
});

instance.create(bookmark);

The example above creates a bookmark with a GoToAction, which takes the user to a destination (page 3) in the current document. There are several other actions you can use with bookmarks, such as opening a web link, submitting or resetting a form, or executing a script. These are described in the PDF actions guide.

Linking to URIs

Using the URIAction, you can link to a website from your bookmarks:

const website = new PSPDFKit.Bookmark({
  name: "PSPDFKit website",
  action: new PSPDFKit.Actions.URIAction({
    uri: "https://pspdfkit.com"
  })
});

instance.create(website);

We use cookies to improve your experience and for marketing. Learn more in our privacy policy.