---
title: "Retrieving highlighted text"
canonical_url: "https://www.nutrient.io/guides/android/prebuilt-solutions/common-use-cases/retrieving-highlighted-text/"
md_url: "https://www.nutrient.io/guides/android/prebuilt-solutions/common-use-cases/retrieving-highlighted-text.md"
last_updated: "2026-06-18T07:25:36.440Z"
description: "Discover how to retrieve highlighted text with TextMarkupAnnotation in Nutrient. Learn the implementation in Kotlin and Java for efficient text markup managemen"
---

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).

## Retrieving highlighted text

Highlighted text can be retrieved with [`TextMarkupAnnotation#getHighlightedText()`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.annotations/-text-markup-annotation/get-highlighted-text.html):

### KOTLIN

```kotlin

val pageIndex = 0
val annotations: List<Annotation> = document.annotationProvider.getAnnotations(pageIndex)
val highlightedTextMarkups: MutableList<String> = ArrayList()
for (annotation in annotations) {
    if (annotation is TextMarkupAnnotation) {
        val highlightedText = annotation.highlightedText
        highlightedText?.let { highlightedTextMarkups.add(it) }
    }
}

```

### JAVA

```java

final int pageIndex = 0;
List<Annotation> annotations = document.getAnnotationProvider().getAnnotations(pageIndex);
List<String> highlightedTextMarkups = new ArrayList<>();
for (Annotation annotation : annotations) {
    if (annotation instanceof TextMarkupAnnotation) {
        TextMarkupAnnotation textMarkupAnnotation = (TextMarkupAnnotation) annotation;
        String highlightedText = textMarkupAnnotation.getHighlightedText();
        highlightedTextMarkups.add(highlightedText);
    }
}

```

[`TextMarkupAnnotation#getHighlightedText()`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.annotations/-text-markup-annotation/get-highlighted-text.html) may return `null` if no text is highlighted.
---

## Related pages

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

