How to avoid 'annotationChanged' event while importing existing annotations on initial webviewer load?

WebViewer Version: 8.3.3

Do you have an issue with a specific file(s)? No
Can you reproduce using one of our samples or online demos? Yes
Are you using the WebViewer server? No
Does the issue only happen on certain browsers? No
Is your issue related to a front-end framework? Yes
Is your issue related to annotations? Yes

Please give a brief summary of your issue:
(Think of this as an email subject)

How to avoid ‘annotationChanged’ event while importing existing annotations on initial webviewer load?

Please describe your issue and provide steps to reproduce it:
(The more descriptive your answer, the faster we are able to help you)

  • Importing existing annotations on initial load, triggers ‘annotationChanged’ event - How to avoid that?
  • we need ‘annotationChanged’ event only when user manually adds annotations in the UI

Example Code:

import React, {useRef, useEffect} from 'react';
import Webviewer from '@pdftron/webviewer';

const annotations = '<?xml version="1.0" encoding="UTF-8" ?><xfdf xmlns="" xml:space="preserve"><pdf-info xmlns="" version="2" import-version="3" /><fields /><annots><ink page="0" rect="113.500,565.740,283.880,726.400" color="#E44234" flags="print" name="2bff29d1-78d4-f812-1b82-0e4f12eadac7" title="Guest" subject="Free Hand" date="D:20220106170222-08\'00\'" creationdate="D:20220106170220-08\'00\'"><inklist><gesture>114.5,611.64;114.5,610.9;116.74,609.4;117.49,606.41;119.74,602.66;121.98,598.17;124.23,593.6800000000001;127.22,588.45;127.22,586.2;129.47,582.46;130.96,577.97;132.46,574.23;133.96,571.98;134.71,571.23;135.45,568.99;136.2,568.24;</gesture></inklist></ink></annots><pages><defmtx matrix="1,0,0,-1,0,792" /></pages></xfdf>';
const initialDoc = process.env.PUBLIC_URL + "/test4.pdf";

function App() {
    const viewerDiv = useRef<HTMLDivElement>(null);

    useEffect(() => {
            path: "lib",
        }, viewerDiv.current as HTMLDivElement).then(instance => {
            const {documentViewer, annotationManager} = instance.Core;
            documentViewer.addEventListener('documentLoaded', async (event) => {
                console.log('documentLoaded:', event)
                await annotationManager.importAnnotations(annotations);
                // importing existing annotations on initial load, triggering 'annotationChanged' event - How to avoid that?
            annotationManager.addEventListener('annotationChanged', async (event) => {
                console.log('annotationChanged:', event);
    }, []);

    return (
        <div className="App">
            <div className="webviewer" ref={viewerDiv} style={{height: '100vh'}}></div>

export default App;

Please provide a link to a minimal sample where the issue is reproducible:

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:



Unfortunately, the annotationChanged event is unavoidable. However, the AnnotationChangedInfoObject(PDFTron WebViewer Class: AnnotationManager) will be passed to the callback function as a parameter in the annotationChanged event. You could be able to identify if the annotation change is the result of importing annotations using importAnnotations.

1 Like