Some test text!

Hamburger Icon

Web / Guides / Add outline

Add an outline to PDFs using JavaScript

Make sure you have Full API enabled in WebViewer.

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();

Have questions? Connect with our experts on Discord.