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

# Outline tree

Discover how to work with an outline tree using a UI component or API guide. Display outlines & bookmarks on iOS, navigate through PDF documents, and create new bookmarks programmatically. Learn more

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 on iOS

A document outline, or table of contents, demonstrates how the PDF document is organized and helps users see the overall picture. The [`PTOutlineViewController`](https://sdk.apryse.com/api/ios/Classes/PTOutlineViewController.html) class shows the document outline (table of contents) that can be used to navigate through the document being viewed by a [`PTPDFViewCtrl`](https://sdk.apryse.com/api/ios/Classes/PTPDFViewCtrl.html) by tapping on a bookmark item.

![](https://4149080208-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgY6xtY9ZQd9XMpvWlGM0%2Fuploads%2Fgit-blob-9acb375f71cdbf76d2250227df451bef01effd66%2Fa400d02a39898855332fc3a1d2b17effe42eb9a7-1242x2208.png?alt=media)

*The outline control is part of the Tools library, so make sure you have* [*added the Tools library to your project*](/ios/ui-customization/setup.md)*.*

## Show an outline view controller

To create a new outline view controller instance and display it from another view controller, supply a `PTPDFViewCtrl` instance to the `PTOutlineViewController` designated initializer:

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

```swift
// Initialize outline view controller with a PTPDFViewCtrl instance.
let outlineViewController = PTOutlineViewController(pdfViewCtrl: pdfViewCtrl)

// Set the current view controller as the outline view controller's delegate.
outlineViewController.delegate = self

let navigationController = UINavigationController(rootViewController: outlineViewController)
if ( UIDevice.current.userInterfaceIdiom == .pad ) {
    navigationController.modalPresentationStyle = .popover
    navigationController.popoverPresentationController?.barButtonItem = outlineButton
}

self.present(navigationController, animated: true, completion: nil)
```

{% endcode %}
{% endtab %}

{% tab title="Obj-C" %}
{% code lineNumbers="true" %}

```objc
// Initialize outline view controller with a PTPDFViewCtrl instance.
PTOutlineViewController *outlineViewController = [[PTOutlineViewController alloc] initWithPDFViewCtrl:pdfViewCtrl];

// Set the current view controller as the outline view controller's delegate.
outlineViewController.delegate = self;

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:outlineViewController];
if ( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad ) {
    navigationController.modalPresentationStyle = UIModalPresentationPopover;
    navigationController.popoverPresentationController.barButtonItem = self.outlineButton;
}

[self presentViewController:navigationController animated:YES completion:nil];
```

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

{% hint style="info" %}
**The outline view controller must be pushed onto a navigation controller's stack before being shown.**
{% endhint %}

{% hint style="info" %}
**Presenting on iPads:**

The outline view controller is designed to be presented in a popover on iPads. To do so, you must provide the `PTOutlineViewController`'s [`UIPopoverPresentationController`](https://developer.apple.com/uikit/uipopoverpresentationcontroller/) with either:

* a [`sourceRect`](https://developer.apple.com/uikit/uipopoverpresentationcontroller/1622324-sourcerect/) AND
* a [`sourceView`](https://developer.apple.com/uikit/uipopoverpresentationcontroller/1622313-sourceview/)

OR

* a [`barButtonItem`](https://developer.apple.com/uikit/uipopoverpresentationcontroller/1622314-barbuttonitem/)

as in the example above.
{% endhint %}

You can set a delegate to be notified by the outline view controller when outline bookmarks are selected with the `PTOutlineViewControllerDelegate` protocol. (See the CompleteReader example for usage of an `PTOutlineViewController`.)
{% endtab %}

{% tab title="API guide" %}

## API to programmatically read & create outlines / bookmarks

To navigate an outline tree and print its result.

{% tabs %}
{% tab title="Obj-C" %}
{% code lineNumbers="true" %}

```objc
void PrintIndent(PTBookmark *item) 
{
	int ident = [item GetIndent] - 1;
	for (int i=0; i<ident; ++i) {
    printf("  ");
  }
}
void PrintOutlineTree(PTBookmark *item)
{
	for (; [item IsValid]; item=[item GetNext]) {
		PrintIndent(item);
		if ([item IsOpen]) {
			printf("- %s ACTION -> ", [[item GetTitle] UTF8String]);
		}
		else {
			printf("+ %s ACTION -> ", [[item GetTitle] UTF8String]);
		}
		if ([item HasChildren]) {
			PrintOutlineTree([item GetFirstChild]);
		}
	}
}
PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: filename];
PTBookmark *root = [doc GetFirstBookmark];
PrintOutlineTree(root);
```

{% endcode %}
{% endtab %}

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

```swift
func PrintIndent(item: PTBookmark) -> String {
  let indent = item.getIndent() - 1
  var i = 0
  var str = ""
  while i < indent {
    str = str + ("  ")
    i += 1
  }
  return str
}
func PrintOutlineTree(item: PTBookmark) {
  var currentItem = item
  while currentItem.isValid() {
    let indent: String = PrintIndent(item: currentItem)
    if currentItem.isOpen() {
      print("\(indent)- \(currentItem.getTitle()!) ACTION -> ")
    }
    else {
      print("\(indent)+ \(currentItem.getTitle()!) ACTION -> ")
    }
    if currentItem.hasChildren() {
      PrintOutlineTree(item: currentItem.getFirstChild())
    }
    currentItem = currentItem.getNext()
  }
}
let doc: PTPDFDoc = PTPDFDoc(filepath: filename)
let root: PTBookmark = doc.getFirstBookmark()
PrintOutlineTree(item: root)
```

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

[Read, add, edit PDF outlines and bookmarks](/ios/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/ios/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.
