updatePageAnnotation
Modifies an existing annotation on a specific page.
Signature
updatePageAnnotation(
doc: PdfDocumentObject,
page: PdfPageObject,
annotation: PdfAnnotationObject
): PdfTask<boolean>;
Description
This method finds an existing annotation by its id
and updates its properties with the values from the provided annotation
object. This allows you to change an annotation’s position, color, content, or any other attribute.
Like createPageAnnotation
, this modifies the document in memory. Use saveAsCopy
to generate a file with the changes.
Parameters
Name | Type | Description |
---|---|---|
doc | PdfDocumentObject | The handle of the document to modify. |
page | PdfPageObject | The page where the annotation exists. |
annotation | PdfAnnotationObject | The modified annotation object. It must have the same id as the annotation you wish to update. |
Returns
PdfTask<boolean>
A Task
that resolves with true
if the annotation was successfully found and updated.
Example
// Assuming 'engine', 'document', and 'page' are available
async function changeAnnotationColor(annotation) {
// Create a modified copy of the annotation
const updatedAnnotation = {
...annotation,
color: '#FF0000', // Change color to red
rect: { // Also move it
...annotation.rect,
origin: { x: annotation.rect.origin.x, y: annotation.rect.origin.y + 10 }
}
};
try {
const success = await engine.updatePageAnnotation(document, page, updatedAnnotation).toPromise();
if (success) {
console.log(`Annotation ${annotation.id} was updated.`);
// Re-render the page or just the annotation to see the change
}
} catch (error) {
console.error('Failed to update annotation:', error);
}
}
See Also
Last updated on August 14, 2025
Need Help?
Join our community for support, discussions, and to contribute to EmbedPDF's development.