Skip to content
Guides

Access annotations

The steps to access a list of annotations and annotation objects are as follows:

  1. Obtain the page object.
  2. Access the list of annotations from the page object.
  3. Iterate through each annotation object in the list.

This example shows how to access annotations:

Java
CPDFDocument document = readerView.getPDFDocument();
int pageCount = document.getPageCount();
if (pageCount > 0){
  for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) {
    List<CPDFAnnotation> annotations = document.pageAtIndex(pageIndex).getAnnotations();
    if (annotations != null && !annotations.isEmpty() ){
      for (CPDFAnnotation annotation:annotations){
        if (annotation == null || !annotation.isValid()){
           continue;
        }
        // Begin operations on the acquired annotations.
      }
    }
  }
}
kotlin
val document: CPDFDocument = readerView.pdfDocument
val pageCount = document.pageCount
if (pageCount > 0) {
  for (pageIndex in 0 until pageCount) {
    val annotations = document.pageAtIndex(pageIndex).annotations
    if (annotations != null && annotations.isNotEmpty()) {
      for (annotation in annotations) {
        if (annotation == null || !annotation.isValid) {
          continue
        }
        // Begin operations on the acquired annotations.
      }
    }
  }
}