# Download PDF with annotations

**URL:** <https://pdfjs.community/t/download-pdf-with-annotations/670>\
**Category:** Technical Support\
**Tags:** pdfjs-express\
**Created:** [March 29, 2021, 8:39pm UTC](https://pdfjs.community/t/download-pdf-with-annotations/670 "2021-03-29T20:39:49Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![joe1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@joe1](https://pdfjs.community/u/joe1)\
**Post date:** [March 29, 2021, 8:39pm UTC](https://pdfjs.community/t/download-pdf-with-annotations/670/1 "2021-03-29T20:39:49Z")

</div>

**PDF.js Express Version**

**Detailed description of issue**  
I seem to be missing some pieces to make this work. I’ve added a download button and I want to let the user download their copy with annotations. Pretty much exactly what your main demo does.

My questions are:

- How do I get my button to call the onSave?
- Do you have an example of what the save(mergedFileBlob) function should look like to just download without making the user click another button?
- Do you have a working demo that has this functionality?

Below is my code

**Expected behaviour**  
I want the user to download the PDF with their notes

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

**Link to document**  
It’s not really document specific

**Code snippet**

```javascript
 openDoc() {
   // clearing previous loaded doc
    this.viewer.nativeElement.innerHTML = '';
    if (this.wvInstance != null) {
      try {
        this.wvInstance.dispose();
      }
      catch { }
    }
    if (this.selectedDoc != "") {
      WebViewer({
        path: '/lib',
        initialDoc: this.selectedDoc,
        disabledElements: ['leftPanel', 'leftPanelButton', 'signatureToolGroupButton', 'miscToolGroupButton']
      }, this.viewer.nativeElement).then(instance => {
        this.wvInstance = instance;

        const { docViewer, annotManager } = instance;

        // a callback function to some "download" button
        const onSave = async () => {
          const xfdf = await annotManager.exportAnnotations({ links: false, widgets: false });
          //const fileData = await docViewer.getDocument().getFileData({});
          //const blob = new Blob([fileData], { type: 'application/pdf' });

          const data = new FormData();
          data.append('xfdf', xfdf);
          // using the URL
          data.append('file', this.selectedDoc);
          //data.append('file', blob);
          //data.append('license', my_license_key);

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

          console.log(response);

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

          // Do something with blob...
          // save(mergedFileBlob)
        }

      });
    }
  }

  downloadDoc() {

    // how do I call the onSave from above?

  }

```

---

_[View the full topic](https://pdfjs.community/t/download-pdf-with-annotations/670)._
