getAllAnnotations
Retrieves all annotations from every page in the document.
Signature
getAllAnnotations(
doc: PdfDocumentObject
): PdfTask<Record<number, PdfAnnotationObject[]>, PdfAnnotationsProgress>;
Description
This method iterates through the entire document to collect all annotations. Because this can be a long-running operation for large documents, it is designed to provide progress updates.
You can use the .onProgress()
callback to receive annotations for each page as soon as they are processed, allowing you to update your UI incrementally.
Parameters
Name | Type | Description |
---|---|---|
doc | PdfDocumentObject | The handle of the document to retrieve annotations from. |
Returns
PdfTask<Record<number, PdfAnnotationObject[]>, PdfAnnotationsProgress>
A Task
with two payloads: a final result and a progress update.
- Resolved Value: The task resolves with a
Record<number, PdfAnnotationObject[]>
, which is an object mapping each page index to its array of annotations. - Progress Payload: While processing, the task emits progress updates of type
PdfAnnotationsProgress
({ page: number; annotations: PdfAnnotationObject[] }
) for each page.
See Concepts: Tasks for details on handling progress.
Example
// Assuming 'engine' and an open 'document' object are available
function loadAllAnnotations(doc) {
const allAnnotationsTask = engine.getAllAnnotations(doc);
// Listen for progress to update the UI incrementally
allAnnotationsTask.onProgress(progress => {
console.log(`Received ${progress.annotations.length} annotations for page ${progress.page}.`);
// You could render these annotations now
});
// Handle the final result
allAnnotationsTask.toPromise().then(allAnnosByPage => {
console.log('Finished loading all annotations!');
const total = Object.values(allAnnosByPage).reduce((sum, annos) => sum + annos.length, 0);
console.log(`Total annotations in document: ${total}`);
}).catch(error => {
console.error('Failed to get all annotations:', error);
});
}
See Also
Last updated on August 14, 2025
Need Help?
Join our community for support, discussions, and to contribute to EmbedPDF's development.