> 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/add.md).

# Add a bookmark to PDFs on iOS

Learn how to add bookmarks and new outline items in PDF documents with Apryse SDK. Explore code samples for editing outlines and creating bookmarks using high-level API. The Apryse iOS SDK streamlines

To add a bookmark or a new outline item in an existing document.

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

```objc
PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: filename];
PTBookmark *myitem = [PTBookmark Create: doc in_title: @"My Item"];
[doc AddRootBookmark: myitem];
```

{% endcode %}
{% endtab %}

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

```swift
let doc: PTPDFDoc! = PTPDFDoc(filepath: filename)
$myitem = Bookmark::Create($doc, "My Item");
$doc->AddRootBookmark($myitem);
```

{% 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 adding a bookmark

While it's possible to work with outline items or Bookmarks using the SDF API (See section 8.2.2, "Document Outline", in the PDF Reference Manual for more details), Apryse SDK simplifies the process by providing the high-level utility class `PDF.Bookmark`.

Note that we obtain the root Bookmark using `GetFirstBookmark()`. If `GetFirstBookmark()` returns an invalid Bookmark (where `GetFirstBookmark().IsValid()` is false), the document has no outline tree.

Sub-items can be added using the `Bookmark.AddChild()` method:

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

```objc
PTBookmark *sub_item = [myitem AddChildWithTitle: @"My Sub-Item"];
```

{% endcode %}
{% endtab %}

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

```swift
let sub_item: PTBookmark = myitem.addChild(withTitle: "My Sub-Item")
```

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

Note that a Bookmark can be associated with different kinds of Actions. The most common action is to move to another location in the current document. This type of Action is called a Go-To action. The following sample creates a new page Destination and sets the Bookmark's action:

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

```objc
[myitem SetAction: [PTAction CreateGoto: [PTDestination CreateFit: [doc GetPage: 1]]]];
```

{% endcode %}
{% endtab %}

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

```swift
myitem.setAction(PTAction.createGoto(PTDestination.createFit(doc.getPage(1))))
```

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

Using Apryse SDK, it is also possible to quickly create *named* destinations. Named destinations have an advantage over explicit destinations — they allow the location of the destination to change without invalidating existing links.

To create a named destination, pass the key (under which the destination will be stored) to the `Action.Create()` method:

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

```objc
NSData* key = [@"blue1" dataUsingEncoding:NSUTF8StringEncoding]
[myitem SetAction: [PTAction CreateGotoWithNamedDestination: key key_sz: [key length] dest:[PTDestination CreateFit: [doc GetPage: 1]]]];
```

{% endcode %}
{% endtab %}

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

```swift
key = "blue1"
myitem.setAction(PTAction.createGoto(key, key.length, PTDestination.createFit(doc.getPage(1))))
```

{% 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/ios/bookmarks/add.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.
