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:

tsx
// Get the total number of pages in the PDF document
const pageCount = await pdfReaderRef!.current!._pdfDocument.getPageCount();
let allAnnotations: CPDFAnnotation[] = [];
for (let i = 0; i < pageCount; i++) {
  // Retrieve the page object for the corresponding page number
  const page = pdfReaderRef?.current?._pdfDocument.pageAtIndex(i);
  // Get all annotations on the page
  const annotations = await page?.getAnnotations();
  if (annotations) {
    allAnnotations = allAnnotations.concat(annotations);
  }
}