Get previous annotation from annotationChanged event

Hello there,
I am using version 7.2.1

Is there any way to get the previous annotation(the unchanged annotation of which I have changed) in annotationChanged event


Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Hey there,

There is no way to get this information from the annotation changed event.

What you could do is maintain a separate cache of annotations in your application, and grab that version of the annot in the annotationChanged event. Keep in mind that annotations are class references, so you will have to clone them in order to maintain the old state.

Something like this should get you started:

  const annotCache = new Map();

  const cacheAnnot = (annot) => {
    const id = annot.Id;
    const copy = instance.annotManager.getAnnotationCopy(annot);
    annotCache.set(id, copy);

  const getCachedAnnot = (id) => {
    return annotCache.get(id);

  // Clear the cache when a new doc is loaded
  instance.docViewer.on('documentLoaded', () => {

  // create the cache when the annotations are loaded
  instance.docViewer.on('annotationsLoaded', () => {
    const annots = instance.annotManager.getAnnotationsList();
    annots.forEach(annot => {

  instance.annotManager.on('annotationChanged', (annots) => {
    for (const annot of annots) {
      const id = annot.Id;
      const cachedAnnot = getCachedAnnot(id);
      console.log('Old annotation', cachedAnnot);
      console.log('New annotation', annot);


1 Like