# Download pdf with annotations(fields data + signatures)

**URL:** <https://pdfjs.community/t/download-pdf-with-annotations-fields-data-signatures/355>\
**Category:** Technical Support\
**Tags:** pdfjs-express\
**Created:** [October 23, 2020, 6:42pm UTC](https://pdfjs.community/t/download-pdf-with-annotations-fields-data-signatures/355 "2020-10-23T18:42:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![barr.develop](https://avatars.discourse-cdn.com/v4/letter/b/f0a364/32.png) [@barr.develop](https://pdfjs.community/u/barr.develop)\
**Post date:** [October 23, 2020, 6:42pm UTC](https://pdfjs.community/t/download-pdf-with-annotations-fields-data-signatures/355/1 "2020-10-23T18:42:32Z")

</div>

**PDF.js Express Version**  
7.1.2

**Detailed description of issue**  
Trying to download PDF document with added annotations by WebViewer UI using `instance.downloadPdf`, but instead get a file without annotations.

**Expected behaviour**  
To download document with annotations added in Viewer.

**Link to document**

**Code snippet**

```javascript
    WebViewer(...)
  .then(function(instance) {
    var docViewer = instance.docViewer;
    var annotManager = instance.annotManager;

    // you must have a document loaded when calling this api
    docViewer.on('documentLoaded', async function() {
      // download pdf without annotations added by WebViewer UI
      instance.downloadPdf({
        includeAnnotations: false,
      });

      // download pdf with all annotations flattened
      instance.downloadPdf({
        includeAnnotations: true,
        flatten: true,
      });

      // download pdf without links
      const xfdfString = await annotManager.exportAnnotations({ links: false });
      instance.downloadPdf({
        xfdfString: xfdfString,
      });
    });
});

```

---

<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 23, 2020, 7:00pm UTC](https://pdfjs.community/t/download-pdf-with-annotations-fields-data-signatures/355/2 "2020-10-23T19:00:05Z")

</div>

Hi!

PDF.js Express does not support flattening annotations on the client. To get this functionality, you can either use the [merge rest API](https://pdfjs.express/documentation/utils/merge), or try out our sister product, [PDFTron Webviewer](https://www.pdftron.com/webviewer) (which has this functionality client side).

Thanks!  
Logan

---

<div class="post-metadata">

**Author:** ![barr.develop](https://avatars.discourse-cdn.com/v4/letter/b/f0a364/32.png) [@barr.develop](https://pdfjs.community/u/barr.develop)\
**Post date:** [October 23, 2020, 7:43pm UTC](https://pdfjs.community/t/download-pdf-with-annotations-fields-data-signatures/355/3 "2020-10-23T19:43:46Z")

</div>

Thanks, @Logan

Could you please help with advice?  
When I merged annotations with rest API, how is it possible to flatten it?  
I want to get PDF document where all form fields and signature are read-only\static.

---

<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 26, 2020, 2:17pm UTC](https://pdfjs.community/t/download-pdf-with-annotations-fields-data-signatures/355/4 "2020-10-26T14:17:59Z")

</div>

Hi there!

Before you export the annotations, you can loop over them and set them as readonly.

```javascript
const { annotManager } = instance;
const list = annotManager.getAnnotationsList();

list.forEach(item => {
  item.ReadOnly = true
});

const xfdf = await annotManager.exportAnnotations();
...

```

Keep in mind that a lot of PDF viewers do not honour the ReadOnly flag, so the document may still be editable in some viewers.

Thanks!  
Logan

---

<div class="post-metadata">

**Author:** ![Steven](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@Steven](https://pdfjs.community/u/Steven)\
**Post date:** [February 18, 2021, 11:15am UTC](https://pdfjs.community/t/download-pdf-with-annotations-fields-data-signatures/355/5 "2021-02-18T11:15:44Z")

</div>

Can I use the “merge rest API” without license key like as a trial?

```
	  const onSave = async () => {
	    const xfdf = await annotManager.exportAnnotations({ links: false, widgets: false });
	    const fileData = await docViewer.getDocument().getFileData({});

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

	    // Process the file
	    const response = await fetch('https://api.pdfjs.express/merge', {
	      method: 'post',
	      body: data
	    }).then(resp => resp.json());

	    const { url, key, id } = response;

	    // Download the file
	    const mergedFileBlob = await fetch(url, {
	      headers: {
	        Authorization: key
	      }
	    }).then(resp => resp.blob())
  }
```

---

<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 22, 2021, 9:25pm UTC](https://pdfjs.community/t/download-pdf-with-annotations-fields-data-signatures/355/6 "2021-02-22T21:25:21Z")

</div>

Yes! The API can be used without a license key, however please note that the output will be watermarked and/or mangled.

> **[Development | Documentation](https://pdfjs.express/documentation/utils/development)**

Thanks,  
Logan
