# Importing XFDF has failed

**URL:** https://pdfjs.community/t/importing-xfdf-has-failed/1006
**Category:** Technical Support
**Created:** [September 29, 2021, 6:43am UTC](https://pdfjs.community/t/importing-xfdf-has-failed/1006 "2021-09-29T06:43:58Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![crossbim001](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@crossbim001](https://pdfjs.community/u/crossbim001)
#### Post date: [September 29, 2021, 6:43am UTC](https://pdfjs.community/t/importing-xfdf-has-failed/1006/1 "2021-09-29T06:43:58Z")

</div>

PDF.js Express Version: 8.x.x

**We exported annotations as XFDFs, but could not import XFDFs. We tried to pass xfdfString value to annotationManager.importAnnotCommand(xfdfString) function. The result is empty array. We would like to know how we could import XFDFs.**

Here is what we referenced.

> **[Import & Export Annotations using Files with PDF.js Express | Documentation](https://pdfjs.express/documentation/annotation/import-export/files)**

**The below code is about exporting XFDFs.**

\<?xml version="1.0" encoding="UTF-8" ?\> 

Here is importing code:

```javascript
useEffect(() => {
    WebViewer(
      {
        path: '../../../webviewer/lib',
        initialDoc: 'https://s3.ap-northeast-2.amazonaws.com/crossxxx/xxx/drive/wGmxxxx.pdf',
      },
      viewer.current
    ).then((instance) => {
      const { annotationManager, documentViewer } = instance.Core

      // load the annotation data as a transaction command
      fetch('https://apixxx.crossxxxx.cxxxx/pdf-web/715', {
        method: 'GET',
      }).then((response) => {
        if (response.status === 200) {
          response.text().then(async (xfdfString) => {
            console.log('xfdfString', xfdfString)
            // <xfdf>
            // <add>
            // <text subject="Comment" page="0" color="#FFE6A2" ... />
            // </add>
            // <modify />
            // <delete />
            // </xfdf>
            const annotations = await annotationManager.importAnnotCommand(xfdfString) // empty array is returned
            console.log('annotations', annotations)

            annotations.forEach((annotation) => {
              annotationManager.redrawAnnotation(annotation)
            })
          })
        }
      })
    })
},[])

```

Please let us know what to do.

Thanks in advance,  
Heejung

---

<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, 6:44am UTC](https://pdfjs.community/t/importing-xfdf-has-failed/1006/2 "2021-09-29T06:44:03Z")

</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)
- [Real-time collaboration client](https://pdfjs.express/documentation/collaboration/realtime-collaboration-client.8)
- [PDF.js Express Documentation - Annotation](https://pdfjs.express/documentation#annotation)

APIs:
- [PDF.js Express Utilities](https://pdfjs.express/api/utils/index.html#__anchor)
- [ExpressUtils(optionsopt) - # async set() → {Promise.}](https://pdfjs.express/api/utils/ExpressUtils.html#set__anchor)
- [Core](https://pdfjs.express/api/Core.html#__anchor)

Forums:
- [How to merge signature annotation with PDF document](https://pdfjs.community/t/how-to-merge-signature-annotation-with-pdf-document/558/1)
- [How to disable widgets and links using exportAnnotCommand](https://pdfjs.community/t/how-to-disable-widgets-and-links-using-exportannotcommand/981/1)
- [Field values not encoded properly](https://pdfjs.community/t/field-values-not-encoded-properly/380/1)

---

<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:30pm UTC](https://pdfjs.community/t/importing-xfdf-has-failed/1006/3 "2021-09-29T17:30:42Z")

</div>

Hi there,

`importAnnotCommand` is the wrong function to use to import annotations, instead, use `importAnnotations`.

Thanks!  
Logan

---

<div class="post-metadata">

### Author: ![crossbim001](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@crossbim001](https://pdfjs.community/u/crossbim001)
#### Post date: [October 1, 2021, 5:23am UTC](https://pdfjs.community/t/importing-xfdf-has-failed/1006/4 "2021-10-01T05:23:59Z")

</div>

Hi Logan,

We changed the code as you suggested, but it didn’t work, still empty array returned.

const annotations = await annotManager.importAnnotations(xfdfString)

Could you provide us an example regarding exporting and importing? It would be helpful to us.

Best,  
Hee Jung

---

<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 4, 2021, 7:09pm UTC](https://pdfjs.community/t/importing-xfdf-has-failed/1006/5 "2021-10-04T19:09:57Z")

</div>

Hi,

Sorry I made a mistake, `importAnnotCommand` is the correct function based off of the sample XFDF code in your code snippet.

Can you send me the entire xfdfString?

Also, we recommend not using annotation commands and instead just using normal XFDF.

To export:

```javascript
const xfdfString = await instance.Core.annotationManager.exportAnnotations();

```

To import:

```javascript
instance.Core.annotationManager.importAnnotations(xfdfString)

```

Thanks,  
Logan

---

<div class="post-metadata">

### Author: ![crossbim001](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@crossbim001](https://pdfjs.community/u/crossbim001)
#### Post date: [October 6, 2021, 6:02am UTC](https://pdfjs.community/t/importing-xfdf-has-failed/1006/6 "2021-10-06T06:02:20Z")

</div>

It works. Thank you!

---

<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 6, 2021, 8:25pm UTC](https://pdfjs.community/t/importing-xfdf-has-failed/1006/7 "2021-10-06T20:25:55Z")

</div>


