> 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/android/annotation/annot-style.md).

# Customize annotation style properties

Learn how to easily edit annotation styles with the AnnotEdit tool class. Change border color, thickness, fill color, opacity, and more in your PDF documents. Click for step-by-step instructions! The

{% hint style="info" %}
[`AnnotEdit`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/tools/AnnotEdit.html) tool class can edit the style of a selected annotation easily by using [annotation style dialog ](/android/annotation/style-editor-dialog.md). You can set `AnnotEdit` tool to `ToolManager` as described here: [change tool mode ](/android/ui-customization/set-tool-to-toolmanager.md).
{% endhint %}

With Apryse library, you can change annotation styles such as border color, border thickness, fill color, etc. To change annotation style, you must lock PDF document first. For more information about locking document, see: [document locking](/android/open-save-document/lock.md).

## Changing an annotation border thickness

To change an annotation border thickness:

1. Get the [`BorderStyle`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/Annot.BorderStyle.html) from the annotation by calling [`annot.getBorderStyle()`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/Annot.html#getBorderStyle\(\)).
2. Set thickness to the `BorderSytle` by calling [`borderStyle.setWidth(double)`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/Annot.BorderStyle.html#setWidth\(double\)).
3. Refresh the annotation appearance by calling [`annot.refreshAppearance()`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/Annot.html#refreshAppearance\(\)).
4. Update the `PDFViewCtrl` contents by calling [`pdfViewCtrl.update()`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/PDFViewCtrl.html#update\(\)).

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

```java
void changeAnnotThickness(final PDFViewCtrl pdfViewCtrl, final Annot annot, final double thickness) throws Exception {
    // Locks the document first as accessing annotation/doc
    // information isn't thread safe.
    pdfViewCtrl.docLock(true, new PDFViewCtrl.LockRunnable() {
        @Override
        public void run() throws Exception {
            Annot.BorderStyle borderStyle = annot.getBorderStyle();
            borderStyle.setWidth(thickness);

            annot.refreshAppearance();
            pdfViewCtrl.update();
        }
    });
}
```

{% endcode %}
{% endtab %}

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

```kotlin
fun changeAnnotThickness(pdfViewCtrl: PDFViewCtrl, annot: Annot, thickness: Double) { 
    // Locks the document first as accessing annotation/doc
    // information isn't thread safe.
    pdfViewCtrl.docLock(true) {
        val borderStyle = annot.borderStyle
        borderStyle.width = thickness
        annot.refreshAppearance()
        pdfViewCtrl.update()
    }
}
```

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

{% hint style="info" %}
To make annotation border invisible, call `borderStyle.setWidth(0)`.
{% endhint %}

## Changing an annotation border color.

If there is a [`FreeText`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/annots/FreeText.html) annotation, to set the border color of the annotation, call \[`freeText.setLineColor(ColorPt, int)`]\(<https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/annots/FreeText.html#setLineColor(com.pdftron.pdf.ColorPt>, int)). To set the border color of the other annotation types, call \[`annot.setColor(ColorPt, int)`]\(<https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/Annot.html#setColor(com.pdftron.pdf.ColorPt>, int)).

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

```java
void changeAnnotBorderColor(final PDFViewCtrl pdfViewCtrl, final Annot annot, final @ColorInt int color) throws Exception {
    // Locks the document first as accessing annotation/doc
    // information isn't thread safe.
    pdfViewCtrl.docLock(true, new PDFViewCtrl.LockRunnable() {
        @Override
        public void run() throws Exception {
            ColorPt colorPt = Utils.color2ColorPt(color);
            // if color is transparent, then color component number is 0.
            int colorCompNum = color == Color.TRANSPARENT ? 0 : 3;
            // if the annotation is a FreeText annotation
            if (annot.getType() == Annot.e_FreeText) {
                FreeText freeText = new FreeText(annot);
                freeText.setLineColor(colorPt, colorCompNum);
            } else {
                annot.setColor(colorPt, colorCompNum);
            }

            annot.refreshAppearance();
            pdfViewCtrl.update();
        }
    });
}
```

{% endcode %}
{% endtab %}

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

```kotlin
fun changeAnnotBorderColor(pdfViewCtrl: PDFViewCtrl, annot: Annot, @ColorInt color: Int) { 
    // Locks the document first as accessing annotation/doc
    // information isn't thread safe.
    pdfViewCtrl.docLock(true, object : LockRunnable {
        @Throws(Exception::class)
        override fun run() {
            val colorPt: ColorPt = Utils.color2ColorPt(color)
            // if color is transparent, then color component number is 0.
            val colorCompNum: Int = if (color == Color.TRANSPARENT) 0 else 3
            // if the annotation is a FreeText annotation
            if (annot.type == Annot.e_FreeText) {
                val freeText = FreeText(annot)
                freeText.setLineColor(colorPt, colorCompNum)
            } else {
                annot.setColor(colorPt, colorCompNum)
            }
            annot.refreshAppearance()
            pdfViewCtrl.update()
        }
    })
}
```

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

{% hint style="info" %}
To set the color of a [`Text`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/annots/Text.html) annotation, call `annot.setColor(ColorPt, int)`.
{% endhint %}

## Changing an annotation opacity

To change the opacity of a [`Markup`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/annots/Markup.html) annotation, call[`Markup.setOpacity(double)`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/annots/Markup.html#setOpacity\(double\)):

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

```java
void changeAnnotOpacity(final PDFViewCtrl pdfViewCtrl, final Annot annot, final double opacity) throws Exception {
    // Locks the document first as accessing annotation/doc
    // information isn't thread safe.
    pdfViewCtrl.docLock(true, new PDFViewCtrl.LockRunnable() {
        @Override
        public void run() throws Exception {
            // if the annotation is a markup annotation,
            // set opacity to the annotation
            if (annot.isMarkup()) {
            Markup markup = new Markup(annot);
            markup.setOpacity(opacity);
            }
            
            annot.refreshAppearance();
            pdfViewCtrl.update();
        }
    });
}
```

{% endcode %}
{% endtab %}

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

```kotlin
fun changeAnnotOpacity(pdfViewCtrl: PDFViewCtrl, annot: Annot, opacity: Double) { 
    // Locks the document first as accessing annotation/doc
    // information isn't thread safe.
    pdfViewCtrl.docLock(true) {
        // if the annotation is a markup annotation,
        // set opacity to the annotation
        if (annot.isMarkup) {
            val markup = Markup(annot)
            markup.opacity = opacity
        }
        annot.refreshAppearance()
        pdfViewCtrl.update()
    }
}
```

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

## Changing an annotation fill color

To set the fill color of a `Markup` annotation, call \[`Markup.setInteriorColor(ColorPt, int)`]\(<https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/annots/Markup.html#setInteriorColor(com.pdftron.pdf.ColorPt>, int)).

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

```java
void changeAnnotInteriorColor(final PDFViewCtrl pdfViewCtrl, final Annot annot, @ColorInt final int color) throws Exception {
    // Locks the document first as accessing annotation/doc
    // information isn't thread safe.
    pdfViewCtrl.docLock(true, new PDFViewCtrl.LockRunnable() {
        @Override
        public void run() throws Exception {
            ColorPt colorPt = Utils.color2ColorPt(color);
            // if color is transparent, then color component number is 0.
            int colorCompNum = color == Color.TRANSPARENT ? 0 : 3;
            // if the annotation is a Markup annotation,
            // set interior color to the annotation.
            if (annot.isMarkup()) {
                Markup markup = new Markup(annot);
                markup.setInteriorColor(colorPt, colorCompNum);
            }
            // refresh the annotation appearch
            annot.refreshAppearance();
            pdfViewCtrl.update();
        }
    });
}
```

{% endcode %}
{% endtab %}

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

```kotlin
fun changeAnnotInteriorColor(pdfViewCtrl: PDFViewCtrl, annot: Annot, @ColorInt color: Int) { 
    // Locks the document first as accessing annotation/doc
    // information isn't thread safe.
    pdfViewCtrl.docLock(true) {
        val colorPt = Utils.color2ColorPt(color)
        // if color is transparent, then color component number is 0.
        val colorCompNum = if (color == Color.TRANSPARENT) 0 else 3
        // if the annotation is a Markup annotation,
        // set interior color to the annotation.
        if (annot.isMarkup) {
            val markup = Markup(annot)
            markup.setInteriorColor(colorPt, colorCompNum)
        }
        // refresh the annotation appearch
        annot.refreshAppearance()
        pdfViewCtrl.update()
    }
}
```

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

## Changing a Text annotation icon

To change a [`Text`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/annots/Text.html) annotation icon, call [`Text.setIcon(String)`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/annots/Text.html#setIcon\(java.lang.String\)). After changing the icon, you must refresh the annotation appearance by calling \[`AnnotUtils.refreshStickyNoteAppearance(Annot, PDFViewCtrl)`]\(<https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/utils/AnnotUtils.html#refreshStickyNoteAppearance(Annot>, PDFViewCtrl)).

{% hint style="info" %}
For available icons, see: [default icons table ](/android/annotation/customize-color-picker.md#default-icons-table).
{% endhint %}

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

```java
void changeAnnotInteriorColor(final PDFViewCtrl pdfViewCtrl, final Annot annot, final String icon) throws Exception {
    // Locks the document first as accessing annotation/doc
    // information isn't thread safe.
    pdfViewCtrl.docLock(true, new PDFViewCtrl.LockRunnable() {
        @Override
        public void run() throws Exception {
            Text text = new Text(annot);
            text.setIcon(icon);
            // refresh the annotation appearch
            AnnotUtils.refreshStickyNoteAppearance(annot, pdfViewCtrl);
            pdfViewCtrl.update();
        }
    });
}
```

{% endcode %}
{% endtab %}

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

```kotlin
fun changeAnnotInteriorColor(pdfViewCtrl: PDFViewCtrl, annot: Annot?, icon: String?) { 
    // Locks the document first as accessing annotation/doc
    // information isn't thread safe.
    pdfViewCtrl.docLock(true) {
        val text = Text(annot)
        text.setIcon(icon)
        // refresh the annotation appearch
        AnnotUtils.refreshStickyNoteAppearance(annot, pdfViewCtrl)
        pdfViewCtrl.update()
    }
}
```

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

## Changing a FreeText annotation text color

To change the text color of a [`FreeText`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/annots/FreeText.html) annotation, call \[`FreeText.setTextColor(ColorPt, int)`]\(<https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/annots/FreeText.html#setTextColor(com.pdftron.pdf.ColorPt>, int)).

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

```java
void changeFreeTextColor(final PDFViewCtrl pdfViewCtrl, final Annot annot, @ColorInt final int color) throws Exception {

    // Locks the document first as accessing annotation/doc
    // information isn't thread safe.
    pdfViewCtrl.docLock(true, new PDFViewCtrl.LockRunnable() {
        @Override
        public void run() throws Exception {
            ColorPt colorPt = Utils.color2ColorPt(color);
            // set FreeText annotation text color
            FreeText freeText = new FreeText(annot);
            freeText.setTextColor(colorPt, 3);

            annot.refreshAppearance();
            pdfViewCtrl.update();
        }
    });
}
```

{% endcode %}
{% endtab %}

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

```kotlin
fun changeFreeTextColor(pdfViewCtrl: PDFViewCtrl, annot: Annot, @ColorInt color: Int) {
    // Locks the document first as accessing annotation/doc
    // information isn't thread safe.
    pdfViewCtrl.docLock(true) {
        val colorPt = Utils.color2ColorPt(color)
        // set FreeText annotation text color
        val freeText = FreeText(annot)
        freeText.setTextColor(colorPt, 3)
        annot.refreshAppearance()
        pdfViewCtrl.update()
    }
}
```

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

## Changing a FreeText annotation text size

To change the text size of a `FreeText` annotation, call [`FreeText.setFontSize(double)`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/annots/FreeText.html#setFontSize\(double\)).

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

```java
void changeFreeTextSize(final PDFViewCtrl pdfViewCtrl, final Annot annot, final double textSize) throws Exception {
    // Locks the document first as accessing annotation/doc
    // information isn't thread safe.
    pdfViewCtrl.docLock(true, new PDFViewCtrl.LockRunnable() {
        @Override
        public void run() throws Exception {
            // set FreeText annotation text color
            FreeText freeText = new FreeText(annot);
            freeText.setFontSize(textSize);
            // refresh the annotation appearance
            annot.refreshAppearance();
            pdfViewCtrl.update();
        }
    });
}
```

{% endcode %}
{% endtab %}

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

```kotlin
fun changeFreeTextSize(pdfViewCtrl: PDFViewCtrl, annot: Annot, textSize: Double) { 
    // Locks the document first as accessing annotation/doc
    // information isn't thread safe.
    pdfViewCtrl.docLock(true) {
        // set FreeText annotation text color
        val freeText = FreeText(annot)
        freeText.fontSize = textSize
        // refresh the annotation appearance
        annot.refreshAppearance()
        pdfViewCtrl.update()
    }
}
```

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

## Changing a FreeText annotation font

The follow code snippet shows how to set the font to a `FreeText` annotation:

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

```java
void changeFreeTextFont(final PDFViewCtrl pdfViewCtrl, final Annot annot, final String fontStr) throws Exception {
    // Locks the document first as accessing annotation/doc
    // information isn't thread safe.
    pdfViewCtrl.docLock(true, new PDFViewCtrl.LockRunnable() {
        @Override
        public void run() throws Exception {
            // set FreeText annotation text color
            FreeText textAnnot = new FreeText(annot);
            String fontDRName = "F0";

            // Create a DR entry for embedding the font
            Obj annotObj = textAnnot.getSDFObj();
            Obj drDict = annotObj.putDict("DR");
            Obj fontDict = drDict.putDict("Font");

            // Embed the font
            Font font = Font.create(pdfViewCtrl.getDoc(), fontStr, textAnnot.getContents());
            fontDict.put(fontDRName, font.GetSDFObj());
            String fontName = font.getName();

            // Set DA string
            String DA = textAnnot.getDefaultAppearance();
            int slashPosition = DA.indexOf("/", 0);

            // if DR string contains '/' which it always should.
            if (slashPosition > 0) {
                String beforeSlash = DA.substring(0, slashPosition);
                String afterSlash = DA.substring(slashPosition);
                String afterFont = afterSlash.substring(afterSlash.indexOf(" "));
                String updatedDA = beforeSlash + "/" + fontDRName + afterFont;

                textAnnot.setDefaultAppearance(updatedDA);

                // refresh text annotation appearance
                textAnnot.refreshAppearance();
                pdfViewCtrl.update();
            }
        }
    });
}
```

{% endcode %}
{% endtab %}

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

```kotlin
fun changeFreeTextFont(pdfViewCtrl: PDFViewCtrl, annot: Annot?, fontStr: String?) { 
    // Locks the document first as accessing annotation/doc
    // information isn't thread safe.
    pdfViewCtrl.docLock(true) {
        // set FreeText annotation text color
        val textAnnot = FreeText(annot)
        val fontDRName = "F0"
        // Create a DR entry for embedding the font
        val annotObj = textAnnot.sdfObj
        val drDict = annotObj.putDict("DR")
        val fontDict = drDict.putDict("Font")
        // Embed the font
        val font = Font.create(pdfViewCtrl.doc, fontStr, textAnnot.contents)
        fontDict.put(fontDRName, font.GetSDFObj())
        val fontName = font.name
        // Set DA string
        val DA = textAnnot.defaultAppearance
        val slashPosition = DA.indexOf("/", 0)
        // if DR string contains '/' which it always should.
        if (slashPosition > 0) {
            val beforeSlash = DA.substring(0, slashPosition)
            val afterSlash = DA.substring(slashPosition)
            val afterFont = afterSlash.substring(afterSlash.indexOf(" "))
            val updatedDA = "$beforeSlash/$fontDRName$afterFont"
            textAnnot.defaultAppearance = updatedDA
            // refresh text annotation appearance
            textAnnot.refreshAppearance()
            pdfViewCtrl.update()
        }
    }
}
```

{% 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/android/annotation/annot-style.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.
