# Error when loading xfdf annotations

**URL:** <https://pdfjs.community/t/error-when-loading-xfdf-annotations/1380>\
**Category:** Technical Support\
**Created:** [February 14, 2022, 6:22pm UTC](https://pdfjs.community/t/error-when-loading-xfdf-annotations/1380 "2022-02-14T18:22:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpho](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@mpho](https://pdfjs.community/u/mpho)\
**Post date:** [February 14, 2022, 6:22pm UTC](https://pdfjs.community/t/error-when-loading-xfdf-annotations/1380/1 "2022-02-14T18:22:59Z")

</div>

**Which product are you using?**  
PDF.js Express

**PDF.js Express Version**  
8.2.0

**Detailed description of issue**  
Receiving the following error when trying to load annotations using the annotationManager.importAnnotations function:  
Uncaught (in promise) TypeError: fa.getElementsByTagName is not a function  
at x.P\_ (webviewer-core.min.js:2413:431)  
at x.WW (webviewer-core.min.js:2416:203)  
at webviewer-core.min.js:419:260  
at new Promise ()  
at qa.FQ (webviewer-core.min.js:419:197)  
at a. (view-document.php?did=175&mid=97 &id=243&hide=true:597:43)  
at webviewer-core.min.js:609:402  
at Array.forEach ()  
at a.h.trigger (webviewer-core.min.js:609:338)  
at a.Ha.JQ (webviewer-core.min.js:296:191)

**Expected behaviour**  
Annotations to be loaded successfully on the PDF

**Does your issue happen with every document, or just one?**  
All documents

**Link to document**  
Using a local document to test

**Code snippet**  
docViewer.addEventListener(‘documentLoaded’, async () =\> {  
annotationManager.importAnnotations(loadXfdfString(userId, documentId));  
});

const loadXfdfString = function(userId, documentId) {  
return new Promise(function(resolve) {  
fetch(`../core/annotations-load.php?userId=${userId}&documentId=${documentId}`, {  
method: ‘GET’  
}).then(function(res) {  
if (res.status === 200) {  
res.text().then(function(xfdfString) {  
resolve(xfdfString);  
})  
} else{  
alert(‘Failed to load the XFDF file…’);  
}  
});  
});  
};

---

<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:** [February 14, 2022, 6:23pm UTC](https://pdfjs.community/t/error-when-loading-xfdf-annotations/1380/3 "2022-02-14T18:23:04Z")

</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)
- [Creating custom annotations for your viewer - Saving the custom annotation](https://pdfjs.express/documentation/annotation/custom-annotations.8#saving-the-custom-annotation)

APIs:
- [ExpressUtils(optionsopt) - # async set() → {Promise.}](https://pdfjs.express/api/utils/ExpressUtils.html#set__anchor)
- [Core.Tools.FreeHandHighlightCreateTool - complete()](https://pdfjs.express/api/Core.Tools.FreeHandHighlightCreateTool.html#complete__anchor)
- [UndefinedWebViewer(options, viewerElement)](https://pdfjs.express/api/global.html#WebViewer__anchor)

Forums:
- [Merging XFDF using the Express REST API length exceeded error](https://pdfjs.community/t/merging-xfdf-using-the-express-rest-api-length-exceeded-error/185/5)
- [Do you have any example from PDF to database](https://pdfjs.community/t/do-you-have-any-example-from-pdf-to-database/196/2)
- [Unable to save the transparency to fillColor](https://pdfjs.community/t/unable-to-save-the-transparency-to-fillcolor/242/1)

---

<div class="post-metadata">

**Author:** ![mpho](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@mpho](https://pdfjs.community/u/mpho)\
**Post date:** [February 14, 2022, 7:11pm UTC](https://pdfjs.community/t/error-when-loading-xfdf-annotations/1380/4 "2022-02-14T19:11:08Z")

</div>

Thanks I managed to resolve the issue by changing the import code to:

docViewer.addEventListener(‘documentLoaded’, async () =\> {

```
          let result = await loadXfdfString(userId, documentId);

          await annotationManager.importAnnotations(result);

```

});

---

<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:** [February 16, 2022, 4:05pm UTC](https://pdfjs.community/t/error-when-loading-xfdf-annotations/1380/5 "2022-02-16T16:05:25Z")

</div>

Closed on February 16, 2022, 4:05pm UTC


