Retrieving Highlighted Text
PSPDFKit 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) } } }
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); } }
ℹ️ Note:
TextMarkupAnnotation#getHighlightedText()
may returnnull
if no text is highlighted.