---
title: "Creating markup annotations from page text"
canonical_url: "https://www.nutrient.io/guides/android/annotations/text-markup-annotations/"
md_url: "https://www.nutrient.io/guides/android/annotations/text-markup-annotations.md"
last_updated: "2026-05-26T12:13:20.286Z"
description: "Learn how to create highlight, underline, and strikeout annotations in Nutrient using Kotlin, including retrieving text rectangles from PDF pages."
---

Nutrient provides an abstract class, [`TextMarkupAnnotation`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.annotations/-text-markup-annotation/index.html), for all text markup annotations: [`HighlightAnnotation`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.annotations/-highlight-annotation/index.html), [`SquigglyAnnotation`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.annotations/-squiggly-annotation/index.html), [`UnderlineAnnotation`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.annotations/-underline-annotation/index.html), and [`StrikeOutAnnotation`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.annotations/-strike-out-annotation/index.html).

## Creating markup annotations from page text

You can retrieve text rectangles required to create markup annotations by calling [`PdfDocument#getPageTextRects`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.document/-pdf-document/get-page-text-rects.html).

For example, you’ll highlight the first occurrence of a random string on the page:

### KOTLIN

```kotlin

// Search for the position of text that should be highlighted on the page.
val textToHighlight = "text to highlight"
val textIndexOnPage = document.getPageText(pageIndex).indexOf(textToHighlight)
if (textIndexOnPage >= 0) {
    // Create an annotation from the text rectangles on the page.
    val annotation = HighlightAnnotation(pageIndex, document.getPageTextRects(pageIndex, textIndexOnPage, textToHighlight.length))
    // Add the annotation to the page.
    fragment.addAnnotationToPage(annotation, false)
}

```

### JAVA

```java

// Search for the position of text that should be highlighted on the page.
String textToHighlight = "text to highlight";
int textIndexOnPage = document.getPageText(pageIndex).indexOf(textToHighlight);
if (textIndexOnPage >= 0) {
    // Create an annotation from the text rectangles on the page.
    HighlightAnnotation annotation = new HighlightAnnotation(pageIndex, document.getPageTextRects(pageIndex, textIndexOnPage, textToHighlight.length()));
    // Add the annotation to the page.
    fragment.addAnnotationToPage(annotation, false);
}

```
---

## Related pages

- [Document Title Styling](/guides/android/prebuilt-solutions/common-use-cases/document-title-styling.md)
- [Retrieving Highlighted Text](/guides/android/prebuilt-solutions/common-use-cases/retrieving-highlighted-text.md)
- [Changing Configuration At Runtime](/guides/android/customizing-the-interface/changing-configuration-at-runtime.md)
- [Document Sharing](/guides/android/miscellaneous/document-sharing.md)

