AnnotationManager.exportAnnotations does not export all visible annotations

I have a “save button” in my app that lets the user save the current annotations. Almost always the last annotation (usually a free hand drawing) is not exported, but if I wait for 2 or 3 seconds and click the “save button” again the exported XFDF contains everything that is visible in the viewer. It seems there’s some delay between when an annotation is visible in the viewer and the same annotation is exported by the AnnotationManager. Is there a way to get rid of this delay or otherwise force a push of what is visible in the viewer to the data structures used by the AnnotationManager? Here is the code:

$("SaveButton").on("click", e => {
    annotationManager.exportAnnotations({}).then(xfdf => {
        console.log(xfdf);
    });
}

When th

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:

Guides:APIs:Forums:

Hey there,

In the future, please fill out the issue template fully so we do not need to ask as many follow up questions.

FreeHand annotations have a little delay before they are “published” to allow time for someone to continue drawing after they lift up the mouse button.

That being said, exportAnnotations should wait for all annotations to publish before exporting. Which version of Express are you using?

Thanks,
Logan

@Logan I use version 8.1.0 of pdfjs.express

Hey there,

I cannot reproduce this issue unfortunately. Here is the code im using to test:

  document.addEventListener("keydown", () => {
    i.Core.annotationManager.exportAnnotations().then((xfdf) => {
      const annots = i.Core.annotationManager.getAnnotationsList();
      i.Core.annotationManager.deleteAnnotation(annots);

      i.Core.annotationManager.importAnnotations(xfdf);
    });
  });

Basically I am exporting annotations, then deleting all annots and then reimporting the exported XFDF. Every time import is called all the freehand annotations are there as expected.

Do you have any other code that may be interfering with annotations? Or any other code you think may be relevant?

Thanks,
Logan

@Logan I don’t know if it’s relevant, but the only annotation I allow in my viewer is a free hand one, created this way and activated when the user clicks on a DOM element:

$(function(){
    WebViewer({
            path: '...',
            licenseKey: '',
            initialDoc: 'https://pdftron.s3.amazonaws.com/downloads/pl/webviewer-demo.pdf',
        },
        document.getElementById('viewer')
    ).then(instance => {
        const documentViewer = instance.Core.documentViewer;
        const annotationManager = instance.Core.annotationManager;
        const Tools = instance.Core.Tools;
        const ToolFreeHand = new Tools.FreeHandCreateTool(documentViewer);
        const Annotations = instance.Core.Annotations;
    
        ToolFreeHand.setStyles({
            StrokeThickness: 3,
            StrokeColor: new Annotations.Color(0, 0, 255)
        });
    
        $("#btn-toggleMode").on("click", e => {
            documentViewer.setToolMode(ToolFreeHand);
        });
    
        $("#btn-CommitAnnotations").on("click", e => {
            annotationManager.exportAnnotations({}).then(xfdf => {
                console.log(xfdf);
            });
        });
    
    });
});