Guides
Access Annotations
The steps to access a list of annotations and annotation objects are as follows:
- Obtain the page object.
- Access the list of annotations from the page object.
- 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);
}
}