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

# Add a free text annotation to a PDF on Server/Desktop

Learn how to add free text annotations to a PDF document page with this full code sample. Add or edit various PDF annotations like hyperlinks, stamps, and more. The Apryse Server SDK streamlines secur

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

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

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

// Create a free text
FreeText freetxtannot = FreeText.Create( doc, new Rect(100, 100, 350, 500)  );
freetxtannot.SetContentRect( new Rect( 200, 200, 350, 500 ) );
freetxtannot.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!" );
freetxtannot.SetCalloutLinePoints( new Point(200,300), new Point(150,290), new Point(110,110) );
freetxtannot.SetBorderStyle(new Annot.BorderStyle(Annot.BorderStyle.Style.e_solid, 1, 10, 20 ) );
freetxtannot.SetEndingStyle(Line.EndingStyle.e_ClosedArrow );
freetxtannot.SetColor( new ColorPt( 0, 1, 0 ) );
freetxtannot.SetQuaddingFormat(1);
page.AnnotPushBack(freetxtannot);
freetxtannot.RefreshAppearance();
```

{% endcode %}
{% endtab %}

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

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

// Create a free text
Annots::FreeText freetxtannot = Annots::FreeText::Create( doc, Rect(100, 100, 350, 500)  );
freetxtannot.SetContentRect( Rect( 200, 200, 350, 500 ) );
freetxtannot.SetContents( UString("\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!"	) );
freetxtannot.SetCalloutLinePoints( Point(200,300), Point(150,290), Point(110,110) );
freetxtannot.SetBorderStyle( Annot::BorderStyle( Annot::BorderStyle::e_solid, 1, 10, 20 ), false);
freetxtannot.SetEndingStyle( Line::e_ClosedArrow );
freetxtannot.SetColor( ColorPt( 0, 1, 0 ) );
freetxtannot.SetQuaddingFormat(1);
page.AnnotPushBack(freetxtannot);
freetxtannot.RefreshAppearance();
```

{% endcode %}
{% endtab %}

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

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

// Create a free text
freetxtannot := FreeTextCreate( doc.GetSDFDoc(), NewRect(100.0, 100.0, 350.0, 500.0)  )
freetxtannot.SetContentRect( NewRect(200.0, 200.0, 350.0, 500.0 ) )
freetxtannot.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!"    )
freetxtannot.SetCalloutLinePoints( NewPoint(200.0,300.0), NewPoint(150.0,290.0), NewPoint(110.0,110.0) )
freetxtannot.SetBorderStyle( NewBorderStyle( BorderStyleE_solid, 1.0, 10.0, 20.0 ), false )
freetxtannot.SetEndingStyle( LineAnnotE_ClosedArrow )
freetxtannot.SetColor( NewColorPt( 0.0, 1.0, 0.0 ) )
freetxtannot.SetQuaddingFormat(1)
page.AnnotPushBack(freetxtannot)
freetxtannot.RefreshAppearance()
```

{% endcode %}
{% endtab %}

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

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

// Create a free text
FreeText freetxtannot = FreeText.create(doc, new Rect(100, 100, 350, 500));
freetxtannot.setContentRect(new Rect(200, 200, 350, 500));
freetxtannot.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!");
freetxtannot.setCalloutLinePoints(new Point(200, 300), new Point(150, 290), new Point(110, 110));
freetxtannot.setBorderStyle(new Annot.BorderStyle(Annot.BorderStyle.e_solid, 1, 10, 20));
freetxtannot.setEndingStyle(Line.e_ClosedArrow);
freetxtannot.setColor(new ColorPt(0, 1, 0));
freetxtannot.setQuaddingFormat(1);
page.annotPushBack(freetxtannot);
freetxtannot.refreshAppearance();
```

{% 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 a free text
    const freetxtannot = await PDFNet.FreeTextAnnot.create(doc, new PDFNet.Rect(100, 100, 350, 500));
    await freetxtannot.setContentRect(new PDFNet.Rect(200, 200, 350, 500));
    await freetxtannot.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!');
    await freetxtannot.setCalloutLinePoints(new PDFNet.Point(200, 300), new PDFNet.Point(150, 290), new PDFNet.Point(110, 110));
    const solidLine = await PDFNet.AnnotBorderStyle.create(PDFNet.AnnotBorderStyle.Style.e_solid, 1, 10, 20);
    await freetxtannot.setBorderStyle(solidLine, true);
    await freetxtannot.setEndingStyle(PDFNet.LineAnnot.EndingStyle.e_ClosedArrow);
    const greenColorPt = await PDFNet.ColorPt.init(0, 1, 0, 0);
    await freetxtannot.setColorDefault(greenColorPt); // default value of last param is 0
    await freetxtannot.setQuaddingFormat(1);
    await page.annotPushBack(freetxtannot);
    await freetxtannot.refreshAppearance();
}
PDFNet.runWithCleanup(main);
```

{% endcode %}
{% endtab %}

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

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

// Create a free text
val txtannot = FreeText.create(doc, Rect(100.0, 100.0, 350.0, 500.0))
txtannot.contentRect = Rect(200.0, 200.0, 350.0, 500.0)
txtannot.contents = "\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(Point(200.0, 300.0), Point(150.0, 290.0), Point(110.0, 110.0))
txtannot.borderStyle = BorderStyle(BorderStyle.e_solid, 1, 10, 20)
txtannot.endingStyle = Line.e_ClosedArrow
txtannot.setColor(ColorPt(0.0, 1.0, 0.0))
txtannot.quaddingFormat = 1
page.annotPushBack(txtannot)
txtannot.refreshAppearance()
```

{% endcode %}
{% endtab %}

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

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

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

// Create a free text
$txtannot = FreeText::Create( $doc->GetSDFDoc(), new Rect(100.0, 100.0, 350.0, 500.0)  );
$txtannot->SetContentRect( new Rect( 200.0, 200.0, 350.0, 500.0 ) );
$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( new Point(200.0,300.0), new Point(150.0,290.0), new Point(110.0,110.0) );
$txtannot->SetBorderStyle( new BorderStyle( BorderStyle::e_solid, 1.0, 10.0, 20.0 ), true );
$txtannot->SetEndingStyle( LineAnnot::e_ClosedArrow );
$txtannot->SetColor( new ColorPt( 0.0, 1.0, 0.0 ) );
$txtannot->SetQuaddingFormat(1);
$page->AnnotPushBack($txtannot);
$txtannot->RefreshAppearance();
```

{% endcode %}
{% endtab %}

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

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

# Create a free text
txtannot = FreeText.Create( doc.GetSDFDoc(), Rect(100, 100, 350, 500)  )
txtannot.SetContentRect( Rect( 200, 200, 350, 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( Point(200,300), Point(150,290), Point(110,110) )
txtannot.SetBorderStyle( BorderStyle( BorderStyle.e_solid, 1, 10, 20 ), True )
txtannot.SetEndingStyle( LineAnnot.e_ClosedArrow )
txtannot.SetColor( ColorPt( 0, 1, 0 ) )
txtannot.SetQuaddingFormat(1)
page.AnnotPushBack(txtannot)
txtannot.RefreshAppearance()
```

{% endcode %}
{% endtab %}

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

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

# Create a free text
txtannot = FreeText.Create( doc.GetSDFDoc(), Rect.new(100, 100, 350, 500)  )
txtannot.SetContentRect( Rect.new( 200, 200, 350, 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( Point.new(200,300), Point.new(150,290), Point.new(110,110) )
txtannot.SetBorderStyle( BorderStyle.new( BorderStyle::E_solid, 1, 10, 20 ), false )
txtannot.SetEndingStyle( LineAnnot::E_ClosedArrow )
txtannot.SetColor( ColorPt.new( 0, 1, 0 ) )
txtannot.SetQuaddingFormat(1)
page.AnnotPushBack(txtannot)
txtannot.RefreshAppearance()
```

{% endcode %}
{% endtab %}

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

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

' Create a free text
Dim txtannot As FreeText = FreeText.Create(doc, New Rect(100, 100, 350, 500))
txtannot.SetContentRect(New Rect(200, 200, 350, 500))
' txtannot.SetContents(("" & vbLf& vbLf&"Some swift brown fox snatched a gray hare out of the air by freezing it with an angry glare." + ""& vbLf& vbLf&"Aha!"& vbLf& vbLf&"And there was much rejoicing!"))
txtannot.SetCalloutLinePoints(New Point(200, 300), New Point(150, 290), New Point(110, 110))
txtannot.SetBorderStyle(New Annot.BorderStyle(Annot.BorderStyle.Style.e_solid, 1, 10, 20))
txtannot.SetEndingStyle(Line.EndingStyle.e_ClosedArrow)
txtannot.SetColor(New ColorPt(0, 1, 0))
txtannot.SetQuaddingFormat(1)
first_page.AnnotPushBack(txtannot)
txtannot.RefreshAppearance()
```

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

[Add or edit PDF annotations sample](https://github.com/iKettles/apryse-gitbook/tree/main/core/samples/annotationtest.md?language=java) 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). Code sample is available in C++, C#, Java, Python, Go, PHP, Ruby & 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/freetext-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.
