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

# Add a bookmark to PDFs on Server/Desktop

Learn how to add bookmarks and outline items in PDF documents using Apryse SDK. Full code sample provided for reading, editing outlines, and creating new bookmarks with high-level API. The Apryse Serv

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

Packages are required for production license. Trial keys have unlimited access to all features.

Demo showcases functionality using WebViewer UI.

<a href="https://apryse.com/capabilities#PageManipulation" class="button primary">Package: Page Manipulation</a><a href="https://showcase.apryse.com/create-thumbnail" class="button primary">Live demo</a>
{% endhint %}

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

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

```csharp
PDFDoc doc = new PDFDoc(filename);
Bookmark red = Bookmark.Create(doc, "My Item");
doc.AddRootBookmark(red);
```

{% endcode %}
{% endtab %}

{% tab title="C++" %}
{% code lineNumbers="true" %}

```cpp
PDFDoc doc(filename);
Bookmark myitem = Bookmark::Create(doc, "My Item");
doc.AddRootBookmark(myitem);
```

{% endcode %}
{% endtab %}

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

```go
doc := NewPDFDoc(filename)
myItem := BookmarkCreate(doc, "My Item")
doc.AddRootBookmark(myItem)
```

{% endcode %}
{% endtab %}

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

```java
PDFDoc doc = new PDFDoc(filename);
Bookmark myitem = Bookmark.create(doc, "My Item");
doc.addRootBookmark(myitem);
```

{% endcode %}
{% endtab %}

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

```js
async function main() {
  const doc = await PDFNet.PDFDoc.createFromURL(filename);
  const myitem = await PDFNet.Bookmark.create(doc, 'My Item');
  doc.addRootBookmark(myitem);
}
PDFNet.runWithCleanup(main);
```

{% endcode %}
{% endtab %}

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

```kotlin
val doc = PDFDoc(filename)
val myitem = Bookmark.create(doc, "My Item")
doc.addRootBookmark(myitem)
```

{% endcode %}
{% endtab %}

{% 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 %}

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

```php
$doc = new PDFDoc($filename);
$myitem = Bookmark::Create($doc, "My Item");
$doc->AddRootBookmark($myitem);
```

{% endcode %}
{% endtab %}

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

```python
doc = PDFDoc(filename)
myitem = Bookmark.Create(doc, "My Item")
doc.AddRootBookmark(myitem)
```

{% endcode %}
{% endtab %}

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

```ruby
doc = PDFDoc.new(filename)
myitem = Bookmark.Create(doc, "My Item")
doc.AddRootBookmark(myitem)
```

{% endcode %}
{% endtab %}

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

```vb
Dim doc As PDFDoc = New PDFDoc(filename)
Dim myitem As Bookmark = Bookmark.Create(doc, "My Item")
doc.AddRootBookmark(myitem)
```

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

[Read, add, edit PDF outlines and bookmarks](/core/get-started/samples/bookmarktest.md) Full code sample which illustrates how to read and edit existing outline items and create new bookmarks using the high-level API. Code sample is available in C++, C#, Java, Python, Go, PHP, Ruby & VB.

## 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="C#" %}
{% code lineNumbers="true" %}

```csharp
Bookmark sub_item = myitem.AddChild("My Sub-Item");
```

{% endcode %}
{% endtab %}

{% tab title="C++" %}
{% code lineNumbers="true" %}

```cpp
Bookmark sub_item = myitem.AddChild("My Sub-Item");
```

{% endcode %}
{% endtab %}

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

```go
subItem = myitem.AddChild("My Sub-Item")
```

{% endcode %}
{% endtab %}

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

```java
Bookmark sub_item = myitem.addChild("My Sub-Item");
```

{% endcode %}
{% endtab %}

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

```js
async function main() {
  const sub_item = await myitem.addNewChild('My Sub-Item');
}
PDFNet.runWithCleanup(main);
```

{% endcode %}
{% endtab %}

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

```kotlin
val sub_item = myitem.addChild("My Sub-Item")
```

{% endcode %}
{% endtab %}

{% 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 %}

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

```php
$sub_item = $myitem->AddChild("My Sub-Item");
```

{% endcode %}
{% endtab %}

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

```python
sub_item = myitem.AddChild("My Sub-Item")
```

{% endcode %}
{% endtab %}

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

```ruby
sub_item = myitem.AddChild("My Sub-Item")
```

{% endcode %}
{% endtab %}

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

```vb
Dim sub_item As Bookmark = myitem.AddChild("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="C#" %}
{% code lineNumbers="true" %}

```csharp
myitem.SetAction(pdftron.PDF.Action.CreateGoto(Destination.CreateFit(doc.GetPage(1))));
```

{% endcode %}
{% endtab %}

{% tab title="C++" %}
{% code lineNumbers="true" %}

```cpp
myitem.SetAction(Action::CreateGoto(Destination::CreateFit(doc.GetPage(1))));
```

{% endcode %}
{% endtab %}

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

```go
myItem.SetAction(ActionCreateGoto(DestinationCreateFit(doc.GetPage(1))))
```

{% endcode %}
{% endtab %}

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

```java
myitem.setAction(Action.createGoto(Destination.createFit(doc.getPage(1))));
```

{% endcode %}
{% endtab %}

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

```js
async function main() {
  myitem.setAction(await PDFNet.Action.createGoto(await PDFNet.Destination.createFit(await doc.getPage(1))));
}
PDFNet.runWithCleanup(main);
```

{% endcode %}
{% endtab %}

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

```kotlin
myitem.action = Action.createGoto(Destination.createFit(doc.getPage(1)))
```

{% endcode %}
{% endtab %}

{% 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 %}

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

```php
$myitem->SetAction(Action::CreateGoto(Destination::CreateFit($doc->GetPage(1))));
```

{% endcode %}
{% endtab %}

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

```python
myitem.SetAction(Action.CreateGoto(Destination.CreateFit(doc.GetPage(1))))
```

{% endcode %}
{% endtab %}

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

```ruby
myitem.SetAction(Action.CreateGoto(Destination.CreateFit(doc.GetPage(1))))
```

{% endcode %}
{% endtab %}

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

```vb
myitem.SetAction(pdftron.PDF.Action.CreateGoto(Destination.CreateFit(doc1.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="C#" %}
{% code lineNumbers="true" %}

```csharp
String key = "blue1";
Action blue_action = Action.CreateGoto(key, Destination.CreateFit(doc.GetPage(1));
```

{% endcode %}
{% endtab %}

{% tab title="C++" %}
{% code lineNumbers="true" %}

```cpp
const char* key = "blue1";
Action blue_action = Action::CreateGoto((UChar*)key, Destination::CreateFit(doc.GetPage(1))));
```

{% endcode %}
{% endtab %}

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

```go
key := []byte("blue1")
blueAction := ActionCreateGoto(&key[0], 2, DestinationCreateFit(doc.GetPage(1)))
```

{% endcode %}
{% endtab %}

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

```java
byte[] key = "blue1".getBytes("UTF8");
myitem.setAction(Action.createGoto(key, Destination.createFit(doc.getPage(1))));
```

{% endcode %}
{% endtab %}

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

```js
async function main() {
  const key = 'blue1';
  myitem.setAction(await PDFNet.Action.createGotoWithKey(key, await PDFNet.Destination.createFit(await doc.getPage(1))));
}
PDFNet.runWithCleanup(main);
```

{% endcode %}
{% endtab %}

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

```kotlin
val key = "blue1".toByteArray(Charsets.UTF_8)
myitem.action = Action.createGoto(key, Destination.createFit(doc.getPage(1)))
```

{% endcode %}
{% endtab %}

{% 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 %}

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

```php
$key = "blue1";
$myitem->SetAction(Action::CreateGoto($key, strlen($key), Destination::CreateFit($doc->GetPage(1))));
```

{% endcode %}
{% endtab %}

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

```python
key = bytearray(b"blue1")
myitem.SetAction(Action.CreateGoto(key, len(key), Destination.CreateFit(doc.GetPage(1))))
```

{% endcode %}
{% endtab %}

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

```ruby
key = "blue1"
myitem.SetAction(Action.CreateGoto(key, key.length, Destination.CreateFit(doc.GetPage(1))))
```

{% endcode %}
{% endtab %}

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

```vb
Dim key As String = "blue1"
myitem.SetAction(pdftron.PDF.Action.CreateGoto(key, Destination.CreateFit(doc1.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/core/bookmark/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.
