> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/web/outlines-bookmarks/outline.md).

# Outline tree in documents

Explore how to navigate an outline tree within documents efficiently. Learn about the structure of document outlines, their hierarchy, and interactive navigation features. Optimize your user experienc

{% hint style="info" %}
**Requirements**

*These packages are required to use these features in production. Trial keys have unlimited access to all features*

<a href="https://apryse.com/capabilities#PageManipulation" class="button primary">Package: Page Manipulation</a><a href="https://showcase.apryse.com/edit-table-of-contents-in-a-pdf" class="button primary">Live demo</a>
{% endhint %}

To navigate an outline tree and print its result.

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer({ ... }, viewerElement).then(instance => {
    const { documentViewer } = instance.Core;
    documentViewer.addEventListener('documentLoaded', () => {

        const doc = documentViewer.getDocument();
        doc.getBookmarks().then((bookmarks) => {

            const printOutlineTree = (item, level) => {
                const indent = '   '.repeat(level);
                const name = item.getName();
                console.log(indent + name);
                item.getChildren().map(b => printOutlineTree(b, level+1));
            };

            bookmarks.map((root) => {
                printOutlineTree(root, 0);
            });
        });
    });
});
```

{% endcode %}

[DocumentViewer.getDocument](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#getDocument__anchor) [Document.getBookmarks](https://sdk.apryse.com/api/web/Core.Document.html#getBookmarks__anchor)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer({ ... }, viewerElement).then(instance => {
    const { docViewer } = instance;
    docViewer.on('documentLoaded', () => {

        const doc = docViewer.getDocument();
        doc.getBookmarks().then((bookmarks) => {

            const printOutlineTree = (item, level) => {
                const indent = '   '.repeat(level);
                const name = item.getName();
                console.log(indent + name);
                item.getChildren().map(b => printOutlineTree(b, level+1));
            };

            bookmarks.map((root) => {
                printOutlineTree(root, 0);
            });
        });
    });
});
```

{% endcode %}

[WebViewerInstance](https://sdk.apryse.com/api/web/WebViewerInstance.html) [DocumentViewer.getDocument](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#getDocument__anchor) [Document.getBookmarks](https://sdk.apryse.com/api/web/Core.Document.html#getBookmarks__anchor)
{% endtab %}
{% endtabs %}

## About outline tree

A document may contain a document outline, allowing the user to navigate interactively from one part of the document to another. The outline consists of a tree-structured hierarchy of Outlines, which serve as a "visual table of contents" to display the document's structure to the user.

Each [Outline](https://sdk.apryse.com/api/web/Core.Bookmark.html#toc1__anchor) has a title, a Page, and a scroll offset that specifies where an outline will take a user that clicks on the Outline. The typical action for a [Outline](https://sdk.apryse.com/api/web/Core.Bookmark.html#toc1__anchor) is to move to another location in the current document — although there is an optional parameter to link to a URL instead.

## Expand outlines by default

Pass `autoExpandOutlines: true` in the WebViewer constructor options.

{% tabs %}
{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```js
Webviewer({
    ...,
    fullAPI: true,
    autoExpandOutlines: true,
}, viewerElement).then(instance => {
    // ...
});
```

{% endcode %}
{% endtab %}
{% endtabs %}

Or, use this API to expand outlines.

{% tabs %}
{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```js
instance.UI.OutlinesPanel.setDefaultOptions({
    autoExpandOutlines: true,
});
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/web/outlines-bookmarks/outline.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
