# AnnotationManager.exportAnnotations does not export all visible annotations

**URL:** <https://pdfjs.community/t/annotationmanager-exportannotations-does-not-export-all-visible-annotations/1010>\
**Category:** Technical Support\
**Created:** [September 29, 2021, 4:43pm UTC](https://pdfjs.community/t/annotationmanager-exportannotations-does-not-export-all-visible-annotations/1010 "2021-09-29T16:43:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![raffaelesgarro](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/raffaelesgarro/32/529_2.png) [@raffaelesgarro](https://pdfjs.community/u/raffaelesgarro)\
**Post date:** [September 29, 2021, 4:43pm UTC](https://pdfjs.community/t/annotationmanager-exportannotations-does-not-export-all-visible-annotations/1010/1 "2021-09-29T16:43:00Z")

</div>

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:

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

```

When th

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/1X/ffbcd25c7d423db8d5acd5db201c272f4db306dd.png) [@system](https://pdfjs.community/u/system)\
**Post date:** [September 29, 2021, 4:43pm UTC](https://pdfjs.community/t/annotationmanager-exportannotations-does-not-export-all-visible-annotations/1010/2 "2021-09-29T16:43:05Z")

</div>

**Hello, I’m Ron, an automated tech support bot 🤖**

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

Guides:
- [XFDF format - In PDF.js Express Web Viewer](https://pdfjs.express/documentation/annotation/xfdf#in-pdf.js-express-web-viewer)
- [Customize display authors for annotations - Map a userId to a Display Author](https://pdfjs.express/documentation/annotation/display-authors#map-a-userid-to-a-display-author)
- [PDF.js Express Documentation - Annotation](https://pdfjs.express/documentation#annotation)

APIs:
- [Core.Annotations.RedactionAnnotation - new RedactionAnnotation( [options])](https://pdfjs.express/api/Core.Annotations.RedactionAnnotation.html#RedactionAnnotation__anchor)
- [Core.Annotations.PolygonAnnotation - new PolygonAnnotation( [initializer])](https://pdfjs.express/api/Core.Annotations.PolygonAnnotation.html#PolygonAnnotation__anchor)
- [Core.Annotations.PolylineAnnotation - new PolylineAnnotation( [initializer])](https://pdfjs.express/api/Core.Annotations.PolylineAnnotation.html#PolylineAnnotation__anchor)

Forums:
- [Import fails after editing freetext annotation](https://pdfjs.community/t/import-fails-after-editing-freetext-annotation/289/1)
- [Importing XFDF has failed](https://pdfjs.community/t/importing-xfdf-has-failed/1006/1)
- [Do you have any example from PDF to database](https://pdfjs.community/t/do-you-have-any-example-from-pdf-to-database/196/2)

---

<div class="post-metadata">

**Author:** ![Logan](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/logan/32/13_2.png) [@Logan](https://pdfjs.community/u/Logan)\
**Post date:** [September 29, 2021, 5:36pm UTC](https://pdfjs.community/t/annotationmanager-exportannotations-does-not-export-all-visible-annotations/1010/3 "2021-09-29T17:36:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![raffaelesgarro](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/raffaelesgarro/32/529_2.png) [@raffaelesgarro](https://pdfjs.community/u/raffaelesgarro)\
**Post date:** [October 11, 2021, 3:07pm UTC](https://pdfjs.community/t/annotationmanager-exportannotations-does-not-export-all-visible-annotations/1010/4 "2021-10-11T15:07:48Z")

</div>

@Logan I use version 8.1.0 of [pdfjs.express](http://pdfjs.express)

---

<div class="post-metadata">

**Author:** ![Logan](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/logan/32/13_2.png) [@Logan](https://pdfjs.community/u/Logan)\
**Post date:** [October 12, 2021, 3:40pm UTC](https://pdfjs.community/t/annotationmanager-exportannotations-does-not-export-all-visible-annotations/1010/6 "2021-10-12T15:40:34Z")

</div>

Hey there,

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

```javascript
  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

---

<div class="post-metadata">

**Author:** ![raffaelesgarro](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/raffaelesgarro/32/529_2.png) [@raffaelesgarro](https://pdfjs.community/u/raffaelesgarro)\
**Post date:** [October 19, 2021, 8:55am UTC](https://pdfjs.community/t/annotationmanager-exportannotations-does-not-export-all-visible-annotations/1010/7 "2021-10-19T08:55:11Z")

</div>

@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:

```javascript
$(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);
            });
        });
    
    });
});

```
