> 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/android/bookmarks/outline.md).

# Outline tree

Learn how to work with an outline tree in Android using a UI component or API guide. Display and navigate PDF bookmarks programmatically with code samples and examples. The Apryse Android SDK streamli

There are two options to working with an outline tree. First is using a UI component that provides tools to set a bookmark or display the outline. Second is an API guide to programmatically read outline items.

{% tabs %}
{% tab title="UI component" %}

## Display outlines & bookmarks in Android

The [`OutlineDialogFragment`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/controls/OutlineDialogFragment.html) displays a document outline (containing PDF `Bookmarks` that can be used to navigate the PDF document by selecting a bookmark item.

![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-70d682efd843654067aaa1eda10edfa72af76763%2Fcf7d5120d7c199b14fec80aefd804b573704dac8-810x1710.png?alt=media)

## Show outline dialog

To show an outline dialog fragment in your activity, create a new instance of [`OutlineDialogFragment`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/controls/OutlineDialogFragment.html) by calling `newInstance()` and setting the [`PDFViewCtrl`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/PDFViewCtrl.html):

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

```java
BookmarksDialogFragment showBookmarksDialog(FragmentManager fragmentManager, PDFViewCtrl pdfViewCtrl) {
    DialogFragmentTab outlineDialog = new DialogFragmentTab(
        UserBookmarkDialogFragment.class,
        BookmarksTabLayout.TAG_TAB_OUTLINE,
        null,
        "Outline",
        "Bookmarks Dialog",
        null);
    ArrayList<DialogFragmentTab> dialogFragmentTabs = new ArrayList<>();
    dialogFragmentTabs.add(outlineDialog);

    BookmarksDialogFragment bookmarksDialog = BookmarksDialogFragment.newInstance();
    bookmarksDialog.setPdfViewCtrl(pdfViewCtrl)
        .setDialogFragmentTabs(dialogFragmentTabs);
    bookmarksDialog.setStyle(DialogFragment.STYLE_NO_TITLE, R.style.PDFTronAppTheme);   
    bookmarksDialog.show(fragmentManager, "bookmarks_dialog");
    return bookmarksDialog;
}
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
fun showBookmarksDialog(fragmentManager: FragmentManager, pdfViewCtrl: PDFViewCtrl): BookmarksDialogFragment {
    val outlineDialog = DialogFragmentTab(
        UserBookmarkDialogFragment::class.java!!,
        BookmarksTabLayout.TAG_TAB_OUTLINE, null,
        "Outline",
        "Bookmarks Dialog", null)
    val dialogFragmentTabs = ArrayList<DialogFragmentTab>()
    dialogFragmentTabs.add(outlineDialog)
    
    val bookmarksDialog = BookmarksDialogFragment.newInstance()
    bookmarksDialog.setPdfViewCtrl(pdfViewCtrl)
                   .setDialogFragmentTabs(dialogFragmentTabs)
    bookmarksDialog.setStyle(DialogFragment.STYLE_NO_TITLE, R.style.PDFTronAppTheme)
    bookmarksDialog.show(fragmentManager, "bookmarks_dialog")
    return bookmarksDialog
}
```

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

You can also set the current bookmark using `setCurrentBookmark(Bookmark)`.

## Listener

You can set a listener to be notified when an item in an [`OutlineDialogFragment`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/controls/OutlineDialogFragment.html) is clicked by calling `setOutlineDialogListener(OutlineDialogListener)`.
{% endtab %}

{% tab title="API guide" %}

## API to programmatically read, edit & create outlines / bookmarks

To navigate an outline tree and print its result.

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

```java
void PrintIndent(Bookmark item) throws PDFNetException {
  int ident = item.getIndent() - 1;
  for (int i = 0; i < ident; ++i) {
    System.out.print("  ");
  }
}
void PrintOutlineTree(Bookmark item) throws PDFNetException {
  for (; item.isValid(); item = item.getNext()) {
    PrintIndent(item);
    System.out.print((item.isOpen() ? "- " : "+ ") + item.getTitle() + " ACTION -> ");
    if (item.hasChildren()) {
      PrintOutlineTree(item.getFirstChild());
    }
  }
}
PDFDoc doc = new PDFDoc(filename);
Bookmark root = doc.getFirstBookmark();
PrintOutlineTree(root);
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
@Throws(PDFNetException::class)
fun PrintIndent(item: Bookmark) {
  val ident = item.indent - 1
  for (i in 0 until ident) {
    print("  ")
  }
}
@Throws(PDFNetException::class)
fun PrintOutlineTree(item: Bookmark) {
  var item = item
  while (item.isValid) {
    PrintIndent(item)
    print((if (item.isOpen) "- " else "+ ") + item.title + " ACTION -> ")
    if (item.hasChildren()) {
      PrintOutlineTree(item.firstChild)
    }
    item = item.next
  }
}
val doc = PDFDoc(filename)
val root = doc.firstBookmark
PrintOutlineTree(root)
```

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

[Read, add, edit PDF outlines and bookmarks](/android/get-started/samples.md#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.
{% 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/android/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.
