This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/android/annotations/text-markup-annotations.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. Creating markup annotations from page text

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

Creating markup annotations from page text

You can retrieve text rectangles required to create markup annotations by calling PdfDocument#getPageTextRects.

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

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