Some test text!

Add bookmark

Add a bookmark to PDFs using JavaScript

Only available with the Full API

To add a bookmark or a new outline item in an existing document.

Webviewer(...).then(async instance => {
  const { documentViewer, PDFNet } = instance.Core;
  await PDFNet.initialize();

  documentViewer.addEventListener('documentLoaded', () => {
    const doc = documentViewer.getDocument();
    const pdfDoc = await doc.getPDFDoc();

    // create bookmark and add it to the first page
    const myitem = await PDFNet.Bookmark.create(pdfDoc, 'My bookmark');
    await myitem.setAction(await PDFNet.Action.createGoto(await PDFNet.Destination.createFit(await pdfDoc.getPage(1))));
    await pdfDoc.addRootBookmark(myitem);

    // refresh document outline
    const bookmarks = await doc.getBookmarks();

Read, add, edit PDF outlines and bookmarks Full code sample which illustrates how to read and edit existing outline items and create new bookmarks using the high-level API

About adding a bookmark

While it's possible to work with outline items or Bookmarks using the SDF API (See section 8.2.2, "Document Outline", in the PDF Reference Manual for more details), PDFTron SDK simplifies the process by providing the high-level utility class PDF.Bookmark.

Get the answers you need: Support

Upcoming Webinar: SDK Features Preview and Live Run-Through | July 14, 2022 at 11 am PT


The Platform


© 2022 PDFTron Systems Inc. All rights reserved.


Terms of Use