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

# Add text annotation to a document on Server/Desktop

Learn how to add a sticky note (text annotation) to a PDF document and edit PDF annotations with this comprehensive code sample. Enhance your PDF files with hyperlinks, stamps, text, shapes, and more!

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

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

```csharp
PDFDoc doc = new PDFDoc(filename);
Page page = doc.GetPage(1);

// Create the sticky note (Text annotation)
Text txt = Text.Create(doc, new Rect( 10, 20, 30, 40 ));
txt.SetIcon("UserIcon");
txt.SetContents("The quick brown fox ate the lazy mouse.");
txt.SetColor(new ColorPt(0,1,0));
txt.RefreshAppearance();
page.AnnotPushBack(txt);
```

{% endcode %}
{% endtab %}

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

```cpp
PDFDoc doc(filename);
Page page = doc.GetPage(1);

// Create the sticky note (Text annotation)
Text txt = Text.Create(doc, Rect(10, 20, 30, 40));
txt.SetIcon("UserIcon");
txt.SetContents("The quick brown fox ate the lazy mouse.");
txt.SetColor(ColorPt(0, 1, 0));
txt.RefreshAppearance();
page.AnnotPushBack(txt);
```

{% endcode %}
{% endtab %}

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

```go
doc := NewPDFDoc(filename)
page := doc.GetPage(1)

// Create the sticky note (Text annotation)
txt := TextCreate( doc.GetSDFDoc(), NewPoint(10.0, 20.0) )
txt.SetIcon( "UserIcon" )
txt.SetContents( "The quick brown fox ate the lazy mouse" )
txt.SetColor( NewColorPt(0.0,1.0,0.0) )
txt.RefreshAppearance()
page.AnnotPushBack( txt )
```

{% endcode %}
{% endtab %}

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

```java
PDFDoc doc = new PDFDoc(filename);
Page page = doc.getPage(1);

// Create the sticky note (Text annotation)
Text txt = Text.create(doc, new Rect( 10, 20, 30, 40 ));
txt.setIcon("UserIcon");
txt.setContents("The quick brown fox ate the lazy mouse.");
txt.setColor(new ColorPt(0,1,0));
txt.refreshAppearance();
page.annotPushBack(txt);
```

{% endcode %}
{% endtab %}

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

```js
async function main() {
    const doc = await PDFNet.PDFDoc.createFromURL(filename);
    const page = await doc.getPage(1);

    // Create the sticky note (Text annotation)
    const txt = await PDFNet.TextAnnot.create(doc, new PDFNet.Rect(10, 20, 30, 40));
    await txt.setIcon("UserIcon");
    await txt.setContents("The quick brown fox ate the lazy mouse.");
    await txt.setColor(await PDFNet.ColorPt.init(0, 1, 0));
    await txt.refreshAppearance();
    await page.annotPushBack(txt);
}
PDFNet.runWithCleanup(main);
```

{% endcode %}
{% endtab %}

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

```kotlin
val doc = PDFDoc(filename)
val page = doc.getPage(1)

// Create the sticky note (Text annotation)
val txt = Text.create(doc, Rect(10.0, 20.0, 30.0, 40.0))
txt.setIcon("UserIcon")
txt.contents = "The quick brown fox ate the lazy mouse."
txt.setColor(ColorPt(0.0,1.0,0.0))
txt.refreshAppearance()
page.annotPushBack(txt)
```

{% endcode %}
{% endtab %}

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

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

```php
$doc = new PDFDoc($filename);
$page = $doc->GetPage(1);

// Create the sticky note (Text annotation)
$txt = Text::Create( $doc->GetSDFDoc(), new Rect( 10.0, 20.0, 30.0, 40.0 ) );
$txt->SetIcon( "UserIcon" );
$txt->SetContents( "The quick brown fox ate the lazy mouse." );
$txt->SetColor( new ColorPt(0.0,1.0,0.0) );
$txt->RefreshAppearance();
$page->AnnotPushBack( $txt );
```

{% endcode %}
{% endtab %}

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

```python
doc = PDFDoc(filename)
page = doc.GetPage(1)

# Create the sticky note (Text annotation)
txt = Text.Create( doc.GetSDFDoc(), Rect( 10, 20, 30, 40 ) )
txt.SetIcon( "UserIcon" )
txt.SetContents( "The quick brown fox ate the lazy mouse." )
txt.SetColor( ColorPt(0,1,0) )
txt.RefreshAppearance()
page.AnnotPushBack( txt )
```

{% endcode %}
{% endtab %}

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

```ruby
doc = PDFDoc.new(filename)
page = doc.GetPage(1)

# Create the sticky note (Text annotation)
txt = Text.Create( doc.GetSDFDoc(), Rect.new( 10, 20, 30, 40 ) )
txt.SetIcon( "UserIcon" )
txt.SetContents( "The quick brown fox ate the lazy mouse." )
txt.SetColor( ColorPt.new(0,1,0) )
txt.RefreshAppearance()
page.AnnotPushBack( txt )
```

{% endcode %}
{% endtab %}

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

```vb
Dim doc As PDFDoc = New PDFDoc(filename)
Dim page As Page = doc.GetPage(1)

' Create the sticky note (Text annotation)
Dim txt As Text = Text.Create(doc, New Rect(10, 20, 30, 40))
txt.SetIcon("UserIcon")
txt.SetContents("The quick brown fox ate the lazy mouse.")
txt.SetColor(New ColorPt(0, 1, 0))
txt.RefreshAppearance()
page.AnnotPushBack(txt)
```

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

[Add or edit PDF annotations](/core/get-started/samples/annotationtest.md) 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). Code sample is available in C++, C#, Java, Python, Go, PHP, Ruby and VB


---

# 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/annotation/text-annotation.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.
