Some test text!

Hamburger Icon

Nodejs / Guides / Outline tree

Navigate PDF outline tree in Node.js

To navigate an outline tree and print its result.

async function main() {
  const printIndent = async(item, str) => {
    const ident = (await item.getIndent()) - 1;
    for (let i = 0; i < ident; ++i) {
      str += '  ';
    return str;
  const printOutlineTree = async(item) => {
    for (; item != null; item = await item.getNext()) {
      let IndentString = await printIndent(item, IndentString);
      let TitleString = await item.getTitle();
      console.log(IndentString + (await item.isOpen()) ? '- ' : '+ ') + TitleString + ' Action -> ');
      if (await item.hasChildren()) {
        await printOutlineTree(await item.getFirstChild());
  const doc = await PDFNet.PDFDoc.createFromURL(filename);
  const root = await docOut.getFirstBookmark();
  await printOutlineTree(root);

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 outline tree

A PDF document may display a document outline on the screen, allowing the user to navigate interactively from one part of the document to another. The outline consists of a tree-structured hierarchy of Bookmarks (sometimes called outline items), which serve as a "visual table of contents" to display the document's structure to the user.

Each Bookmark has a title that appears on screen, and an Action that specifies what happens when a user clicks on the Bookmark. The typical Action for a user-created Bookmark is to move to another location in the current document — although any Action can be specified.

Get the answers you need: Chat with us