This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/android/prebuilt-solutions/common-use-cases/retrieving-highlighted-text.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. Retrieving highlighted text

Nutrient provides an abstract class, TextMarkupAnnotation, for all text markup annotations: HighlightAnnotation, SquigglyAnnotation, UnderlineAnnotation, and StrikeOutAnnotation.

Retrieving highlighted text

Highlighted text can be retrieved with TextMarkupAnnotation#getHighlightedText():

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

TextMarkupAnnotation#getHighlightedText() may return null if no text is highlighted.