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

# Create annotations

Learn how to add sticky notes, links, stamps, and more annotations to PDFs on iOS. Full code samples for adding/editing PDF annotations, including hyperlinks, stamps, highlights, and more. Stamp PDF p

A variety of annotations can be created such as sticky note (text annotations), link annotations, stamp annotations, and more.

{% tabs %}
{% tab title="Text" %}

## Add text annotation to a PDF on iOS

To add a sticky note (text annotation) to a PDF Document.

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

```objc
PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath:filename];
PTPage *page = [doc GetPage:1];

// Create the sticky note (Text annotation)
PTText *txt =
    [PTText Create:[doc GetSDFDoc]
               pos:[[PTPDFRect alloc] initWithX1:10 y1:20 x2:30 y2:40]];
[txt SetTextIconName:@"UserIcon"];
[txt SetContents:@"The quick brown fox ate the lazy mouse."];
[txt SetColor:[[PTColorPt alloc] initWithX:0 y:1 z:0 w:0] numcomp:3];
[txt RefreshAppearance];
[page AnnotPushBack:txt];
```

{% endcode %}
{% endtab %}

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

```swift
let doc: PTPDFDoc = PTPDFDoc(filepath: filename)
let page: PTPage = doc.getPage(1)

// Create the sticky note (Text annotation)
let txt: PTText = PTText.create(doc.getSDFDoc(), pos: PTPDFRect(x1: 10, y1: 20, x2: 30, y2: 40))
txt.setTextIconName("UserIcon")
txt.setContents("The quick brown fox ate the lazy mouse.")
txt.setColor(PTColorPt(x: 0, y: 1, z: 0, w: 0), numcomp: 3)
txt.refreshAppearance()
page.annotPushBack(txt)
```

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

[Add or edit PDF annotations](/ios/get-started/samples.md#annotation) Full code sample which shows how to add or edit PDF annotations (e.g. hyperlink, intra-document link, stamp, rubber stamp, file attachment, sound, text, free-text, line, circle, square, polygon, polyline, highlight, squiggly, caret, and ink).
{% endtab %}

{% tab title="Link" %}

## Create link annotation to a PDF on iOS

To add a hyperlink or intra-document link annotation to a PDF Document page.

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

```objc
PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: filename];
PTPage *page = [doc GetPage:1];

// Create a hyperlink
PTLink *hyperlink = [PTLink CreateWithAction: [doc GetSDFDoc] pos: [[PTPDFRect alloc] initWithX1: 85 y1: 570 x2: 503 y2: 524] action: [PTAction CreateURI: [doc GetSDFDoc] uri: @"http://www.apryse.com"]];
[hyperlink RefreshAppearance];
[page AnnotPushBack: hyperlink];

// Create an intra-document link
PTAction *goto_page_3 = [PTAction CreateGoto: [PTDestination CreateFitH: [doc GetPage:3] top: 0]];
PTLink *link = [PTLink CreateWithAction: [doc GetSDFDoc] pos: [[PTPDFRect alloc] initWithX1: 85 y1: 458 x2: 503 y2: 502] action: goto_page_3];
[link RefreshAppearance];
[page AnnotPushBack: link];
```

{% endcode %}
{% endtab %}

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

```swift
let doc: PTPDFDoc = PTPDFDoc(filepath: filename)
let page: PTPage = doc.getPage(1)

// Create a hyperlink
let hyperlink = PTLink.create(withAction: doc.getSDFDoc(), pos: PTPDFRect(x1: 85, y1: 570, x2: 503, y2: 524), action: PTAction.createURI(doc.getSDFDoc(), uri: "http://www.apryse.com"))
hyperlink.refreshAppearance()
page.annotPushBack(hyperlink)

// Create an intra-document link
let goto_page_3 = PTAction.createGoto(PTDestination.createFitH(doc.getPage(3), top: 0))
let link: PTLink = PTLink.create(withAction: doc.getSDFDoc(), pos: PTPDFRect(x1: 85, y1: 458, x2: 503, y2: 502), action: goto_page_3)
link.refreshAppearance()
page.annotPushBack(link)
```

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

[Add or edit PDF annotations sample](/ios/get-started/samples.md#annotation) Full code sample which shows how to add or edit PDF annotations (e.g. hyperlink, intra-document link, stamp, rubber stamp, file attachment, sound, text, free-text, line, circle, square, polygon, polyline, highlight, squiggly, caret, and ink).
{% endtab %}

{% tab title="Stamp" %}

## Add a stamp annotation to a PDF on iOS

A stamp in a PDF document is analogous to applying a rubber stamp on a paper document.

Apryse SDK benefits include:

* Stamp PDF pages with text, images, or with other PDF pages.
* Embed fonts and images, and copy graphical elements from one page to another.

## Use Stamper to stamp content (text, image, PDF page)

To stamp text, image, and a PDF page to a PDF document.

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

```objc
PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: filename];
PTStamper *s = [[PTStamper alloc] initWithSize_type: e_ptrelative_scale a: 0.05 b: 0.05];

// Specifies if the stamp is to be stamped as an annotation.
// note that stamps created with this setting do not work with SetAsBackground, HasStamps, and DeleteStamps, if annotation is true.
//[s SetAsAnnotation: YES];

[s SetAlignment: e_pthorizontal_right vertical_alignment: e_ptvertical_bottom];
[s SetAlignment: e_pthorizontal_center vertical_alignment: e_ptvertical_top];
[s SetFont: [PTFont Create: [doc GetSDFDoc] type: e_ptcourier embed: YES]];
PTColorPt *red = [[PTColorPt alloc] initWithX: 1 y: 0 z: 0 w: 0];
[s SetFontColor: red]; //set color to red
[s SetTextAlignment: e_ptalign_right];
[s SetAsBackground: YES]; //set text stamp as background
PTPageSet *ps = [[PTPageSet alloc] initWithRange_start: 1 range_end: 2 filter: e_ptall];
[s StampText: doc src_txt: @"This is a title!" dest_pages: ps];

PTImage *img = [PTImage Create: [doc GetSDFDoc] filename: imagename];
[s SetAsBackground: NO]; // set image stamp as foreground
PTPageSet *first_page_ps = [[PTPageSet alloc] initWithOne_page: 1];
[s StampImage: doc src_img: img dest_pages: first_page_ps];

PTPDFDoc *src_doc = [[PTPDFDoc alloc ] initWithFilepath: src_filename];
PTPage *src_page = [src_doc GetPage: 1];
[s StampPage: doc src_page: src_page dest_pages: ps];
```

{% endcode %}
{% endtab %}

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

```swift
let doc: PTPDFDoc = PTPDFDoc(filepath: filename)
let s: PTStamper = PTStamper(size_type: e_ptrelative_scale, a: 0.05, b: 0.05)

// Specifies if the stamp is to be stamped as an annotation.
// note that stamps created with this setting do not work with SetAsBackground, HasStamps, and DeleteStamps, if annotation is true.
//s.setAsAnnotation(true)

s.setAlignment(e_pthorizontal_right, vertical_alignment: e_ptvertical_bottom)
s.setAlignment(e_pthorizontal_center, vertical_alignment: e_ptvertical_top)
s.setFont(PTFont.create(doc.getSDFDoc(), type: e_ptcourier, embed: true))
let red = PTColorPt(x: 1, y: 0, z: 0, w: 0)
s.setFontColor(red) //set color to red
s.setTextAlignment(e_ptalign_right)
s.setAsBackground(true) //set text stamp as background
let ps = PTPageSet(range_start: 1, range_end: 2, filter: e_ptall)
s.stampText(doc, src_txt: "This is a title!", dest_pages: ps)

let img = PTImage.create(doc.getSDFDoc(), filename: imagename)
s.setAsBackground(false)    // set image stamp as foreground
let first_page_ps = PTPageSet(one_page: 1)
s.stampImage(doc, src_img: img, dest_pages: first_page_ps)

let src_doc: PTPDFDoc = PTPDFDoc(filepath: src_filename)
let src_page: PTPage = src_doc.getPage(1)
s.stampPage(doc, src_page: src_page, dest_pages: ps)
```

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

[Stamp a PDF File](/ios/get-started/samples.md#stamper) Full code sample which shows how to stamp PDF pages with text, images, or with other PDF pages and how to add new content (or watermark).

## About Stamper

Stamper can be used for PDF pages with text, images, or with other PDF content in only a few lines of code. Although Stamper is very simple to use compared to ElementBuilder/ElementWriter it is not as powerful or flexible. In case you need full control over PDF creation use ElementBuilder/ElementWriter to add new content to existing PDF pages as shown in the [ElementBuilder sample project ](/ios/get-started/samples.md#elementbuilder).
{% endtab %}

{% tab title="Highlight" %}

## Add highlight annotation to a PDF on iOS

To add a highlight annotation to a PDF Document page.

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

```objc
PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: filename];
PTPage *page = [doc GetPage:1];

// Create a highlight
PTHighlightAnnot *hl = [PTHighlightAnnot Create: [doc GetSDFDoc] pos: [[PTPDFRect alloc] initWithX1: 100 y1: 490 x2: 150 y2: 515]];
[hl SetColor: [[PTColorPt alloc] initWithX: 0 y: 1 z: 0 w: 0] numcomp: 3];
[hl RefreshAppearance];
[page AnnotPushBack: hl];
```

{% endcode %}
{% endtab %}

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

```swift
let doc: PTPDFDoc = PTPDFDoc(filepath: filename)
let page: PTPage = doc.getPage(1)

// Create a highlight
let hl: PTHighlightAnnot = PTHighlightAnnot.create(doc.getSDFDoc(), pos: PTPDFRect(x1: 100, y1: 490, x2: 150, y2: 515))
hl.setColor(PTColorPt(x: 0, y: 1, z: 0, w: 0), numcomp: 3)
hl.refreshAppearance()
page.annotPushBack(hl)
```

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

[Add or edit PDF annotations sample](/ios/get-started/samples.md#annotation) Full code sample which shows how to add or edit PDF annotations (e.g. hyperlink, intra-document link, stamp, rubber stamp, file attachment, sound, text, free-text, line, circle, square, polygon, polyline, highlight, squiggly, caret, and ink).
{% endtab %}

{% tab title="Free text" %}

## Add free text annotation to a PDF on iOS

To add a free text annotation to a PDF Document page.

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

```objc
PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: filename];
PTPage *page = [doc GetPage:1];

// Create a free text
PTFreeText *txtannot = [PTFreeText Create: [doc GetSDFDoc] pos: [[PTPDFRect alloc] initWithX1: 100 y1: 100 x2: 350 y2: 500]];
[txtannot SetContentRect: [[PTPDFRect alloc] initWithX1: 200 y1: 200 x2: 350 y2: 500]];
[txtannot SetContents: @"\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare."
                        "\n\nAha!\n\nAnd there was much rejoicing!"];
[txtannot SetCalloutLinePointsWithKneePoint: [[PTPDFPoint alloc] initWithPx: 200 py: 300] p2: [[PTPDFPoint alloc] initWithPx: 150 py: 290] p3: [[PTPDFPoint alloc] initWithPx: 110 py: 110]];
[txtannot SetBorderStyle: [[PTBorderStyle alloc] initWithS: e_ptsolid b_width: 1 b_hr: 10 b_vr: 20 ] oldStyleOnly: YES];
[txtannot SetEndingStyle: e_ptClosedArrow];
[txtannot SetColor: [[PTColorPt alloc] initWithX: 0 y: 1 z: 0 w: 0] numcomp: 3];
[txtannot SetQuaddingFormat: 1];
[page AnnotPushBack: txtannot];
[txtannot RefreshAppearance];
```

{% endcode %}
{% endtab %}

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

```swift
let doc: PTPDFDoc = PTPDFDoc(filepath: filename)
let page: PTPage = doc.getPage(1)

// Create a free text
let txtannot: PTFreeText = PTFreeText.create(doc.getSDFDoc(), pos: PTPDFRect(x1: 100, y1: 100, x2: 350, y2: 500))
txtannot.setContentRect(PTPDFRect(x1: 200, y1: 200, x2: 350, y2: 500))
txtannot.setContents("\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare." +
    "\n\nAha!\n\nAnd there was much rejoicing!")
txtannot.setCalloutLinePoints(withKneePoint: PTPDFPoint(px: 200, py: 300), p2: PTPDFPoint(px: 150, py: 290), p3: PTPDFPoint(px: 110, py: 110))
//std::vector<double> dash( 2, 2.0 );
txtannot.setBorderStyle(PTBorderStyle(s: e_ptsolid, b_width: 1, b_hr: 10, b_vr: 20), oldStyleOnly: true)
txtannot.setEndingStyle(e_ptClosedArrow)
txtannot.setColor(PTColorPt(x: 0, y: 1, z: 0, w: 0), numcomp: 3)
txtannot.setQuaddingFormat(1)
page.annotPushBack(txtannot)
txtannot.refreshAppearance()
```

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

[Add or edit PDF annotations sample](/ios/get-started/samples.md#annotation) Full code sample which shows how to add or edit PDF annotations (e.g. hyperlink, intra-document link, stamp, rubber stamp, file attachment, sound, text, free-text, line, circle, square, polygon, polyline, free text, squiggly, caret, and ink).
{% endtab %}

{% tab title="Rectangle" %}

## Add rectangle annotation to a PDF on iOS

To add a rectangle annotation to a PDF Document page.

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

```objc
PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: filename];
PTPage *page = [doc GetPage:1];

// Create a rectangle
PTSquare *sq = [PTSquare Create: [doc GetSDFDoc] pos: [[PTPDFRect alloc] initWithX1: 500 y1: 200 x2: 580 y2: 300]];
[sq SetColor: [[PTColorPt alloc] initWithX: 1 y: 0 z: 0 w: 0] numcomp: 3];
[sq SetInteriorColor: [[PTColorPt alloc] initWithX: 0 y: 1 z: 1 w: 0] CompNum: 3];
NSMutableArray *dash = [NSMutableArray arrayWithCapacity: 2];
[dash addObject: @4.0];
[dash addObject: @2.0];
[sq SetBorderStyle: [[PTBorderStyle alloc] initWithS: e_ptdashed b_width: 6 b_hr: 0 b_vr: 0 b_dash: dash] oldStyleOnly: NO];
[sq SetPadding: 4];
[sq RefreshAppearance];
[page AnnotPushBack: sq];
```

{% endcode %}
{% endtab %}

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

```swift
let doc: PTPDFDoc = PTPDFDoc(filepath: filename)
let page: PTPage = doc.getPage(1)

// Create a rectangle
let sq: PTSquare = PTSquare.create(doc.getSDFDoc(), pos: PTPDFRect(x1: 500, y1: 200, x2: 580, y2: 300))
sq.setColor(PTColorPt(x: 1, y: 0, z: 0, w: 0), numcomp: 3)
sq.setInteriorColor(PTColorPt(x: 0, y: 1, z: 1, w: 0), compNum: 3)
let dash = NSMutableArray(capacity: 2)
dash.add(4.0)
dash.add(2.0)
sq.setBorderStyle(PTBorderStyle(s: e_ptdashed, b_width: 6, b_hr: 0, b_vr: 0, b_dash: dash), oldStyleOnly: false)
sq.setPadding(4)
sq.refreshAppearance()
page.annotPushBack(sq)
```

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

[Add or edit PDF annotations sample](/ios/get-started/samples.md#annotation) Full code sample which shows how to add or edit PDF annotations (e.g. hyperlink, intra-document link, stamp, rubber stamp, file attachment, sound, text, free-text, line, circle, square, polygon, polyline, rectangle, squiggly, caret, and ink).
{% 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/annotation/create.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.
