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:

swift
var annotations: [CPDFAnnotation] = []

// Iterate over all pages
for i in 0..<document?.pageCount {
    if let page = document.page(at: i) {
        // terate through all the annotations on the page
        annotations.append(contentsOf: page.annotations)
        
        for annotation in annotations {
            // Process each annotation
        }
    }
}
objective-c
NSMutableArray *annotations = [NSMutableArray array];
// Iterate over all pages
for (int i=0; i<document.pageCount; i++) {
    CPDFPage *page = [document pageAtIndex:i];
  	// Iterate through all the annotations on the page
    [annotations addObjectsFromArray:[page annotations]];
    for (CPDFAnnotation *annotation in annotations) {

    }
}