getPageAnnotations
Retrieves an array of all annotation objects for a specific page.
Signature
getPageAnnotations(
doc: PdfDocumentObject,
page: PdfPageObject
): PdfTask<PdfAnnotationObject[]>;
Description
This method reads the PDF structure and returns a JavaScript representation of every annotation on the given page. The returned array contains objects that conform to the various PdfAnnotationObject
types.
This is the standard way to get the data you need to display, interact with, or modify existing annotations on a specific page.
Parameters
Name | Type | Description |
---|---|---|
doc | PdfDocumentObject | The handle of the document to retrieve annotations from. |
page | PdfPageObject | The specific page object to inspect. |
Returns
PdfTask<PdfAnnotationObject[]>
A Task
that resolves with an array of PdfAnnotationObject
instances. If the page has no annotations, it resolves with an empty array.
See Annotation Models for details on the structure of these objects. The Task
will be rejected if the document or page handle is invalid.
See Concepts: Tasks for more on how to handle asynchronous operations.
Example
// Assuming 'engine' and an open 'document' object are available
async function logAnnotationsForFirstPage(doc) {
try {
const firstPage = doc.pages[0];
const annotations = await engine.getPageAnnotations(doc, firstPage).toPromise();
console.log(`Found ${annotations.length} annotations on page 0.`);
annotations.forEach(anno => {
console.log(`- Annotation ID: ${anno.id}, Type: ${anno.type}`);
});
} catch (error) {
console.error('Failed to get page annotations:', error);
}
}
See Also
Need Help?
Join our community for support, discussions, and to contribute to EmbedPDF's development.