# Merging XFDF using the Express REST API

**URL:** <https://pdfjs.community/t/merging-xfdf-using-the-express-rest-api/105>\
**Category:** Technical Support\
**Created:** [July 1, 2020, 7:37am UTC](https://pdfjs.community/t/merging-xfdf-using-the-express-rest-api/105 "2020-07-01T07:37:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jithinkp](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@jithinkp](https://pdfjs.community/u/jithinkp)\
**Post date:** [July 1, 2020, 7:37am UTC](https://pdfjs.community/t/merging-xfdf-using-the-express-rest-api/105/1 "2020-07-01T07:37:22Z")

</div>

I have tried Merging XFDF using the Express REST API but getting below error when submitting save button.  
{ message: “Invalid input.”, type: “InvalidPDF”, code: 20 }

This is my code

```
WebViewer({
    path: 'lib', // path to the PDFTron 'lib' folder on your server
    licenseKey: 'Insert license key here', // optional
   // initialDoc: 'https://pdftron.s3.amazonaws.com/downloads/pl/webviewer-demo.pdf',
    initialDoc: 'test.pdf', // You can also use documents on your server
}, document.getElementById('viewer'))
    .then(function(instance) {
        var docViewer = instance.docViewer;
        var annotManager = instance.annotManager;

        instance.setHeaderItems(function(header) {
            header.push({
                type: 'actionButton',
                img: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path d="M17 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V7l-4-4zm-5 16c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm3-10H5V5h10v4z"/></svg>',
                onClick: function() {
                    var docViewer = instance.docViewer;
                    var annotManager = instance.annotManager;
                    var xfdf = annotManager.exportAnnotations({ links: false, widgets: false });
                    var fileData = docViewer.getDocument().getFileData({});

                    var data = new FormData();
                    data.append('xfdf', xfdf);
                    data.append('file', fileData);
                    data.append('license','');

                    console.log(data);

                    var response = fetch('https://api.pdfjs.express/xfdf/merge', {
                        method: 'post',
                        body: data
                    }).then(function(resp) {
                        resp.json()
                    });

console.log(response);
                }
            });
        });
    });

```

Please help

---

<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:** [July 2, 2020, 4:06pm UTC](https://pdfjs.community/t/merging-xfdf-using-the-express-rest-api/105/2 "2020-07-02T16:06:08Z")

</div>

Hi there,

`getFileData` returns a promise, so you will need to wait for that to resolve before you can use it.

Also you will want to create a blob with the result from that function.

Something like this:

```javascript
var fileData = await docViewer.getDocument().getFileData({});
var blob = new Blob([fileData], {type: 'application/pdf'})

data.append('file', blob)

```

Hope this helps!  
Logan

---

<div class="post-metadata">

**Author:** ![jithinkp](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@jithinkp](https://pdfjs.community/u/jithinkp)\
**Post date:** [July 3, 2020, 11:09am UTC](https://pdfjs.community/t/merging-xfdf-using-the-express-rest-api/105/4 "2020-07-03T11:09:02Z")

</div>

Hi Logan,

Yes now its working.But i have changed 1.75 mb pdf file and edit some content and requested to merge api.But i got error .“Internal server error” .Also when i try above 3mb pdf file igot another error HTTP content length exceeded 10485760 bytes.

 ![Annotation 2020-07-04 143948](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/1X/92821353eeaab3bd46b043ef4992db9f2424321b.png)

---

<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:** [July 6, 2020, 2:08pm UTC](https://pdfjs.community/t/merging-xfdf-using-the-express-rest-api/105/5 "2020-07-06T14:08:08Z")

</div>

Moved to [Internal server error](https://pdfjs.community/t/internal-server-error/113/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:** [July 6, 2020, 2:08pm UTC](https://pdfjs.community/t/merging-xfdf-using-the-express-rest-api/105/6 "2020-07-06T14:08:10Z")

</div>


