Some test text!

Discord Logo

Chat with us

PDFTron is now Apryse, learn more here.

Web / Guides / Add outline


PDFTron is now Apryse, learn more here.

Add an outline to PDFs using JavaScript

Only available with the Full API

To add a new outline item in an existing document.

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

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

    // create outline and add it to the first page
    const myitem = await PDFNet.Bookmark.create(pdfDoc, 'My outline');
    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();

Get the answers you need: Support