# The mergeDocument() function does not work

**URL:** <https://pdfjs.community/t/the-mergedocument-function-does-not-work/2128>\
**Category:** Technical Support\
**Tags:** pdfjs-express\
**Created:** [October 25, 2022, 3:59pm UTC](https://pdfjs.community/t/the-mergedocument-function-does-not-work/2128 "2022-10-25T15:59:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ytuzet](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/ytuzet/32/1064_2.png) [@ytuzet](https://pdfjs.community/u/ytuzet)\
**Post date:** [October 25, 2022, 3:59pm UTC](https://pdfjs.community/t/the-mergedocument-function-does-not-work/2128/1 "2022-10-25T15:59:21Z")

</div>

**Which product are you using?**  
PDF.js Express Plus on an Angular 13 app

**PDF.js Express Version**  
Original lib version was 7.3.0  
Also tested with 7.3.9 and 8.7.0

**Detailed description of issue**  
From : [PDFJS Express WebViewer Class: Document](https://pdfjs.express/api/7.0/CoreControls.Document.html#mergeDocument__anchor)  
The mergeDocument() function does not work. The function is being called, but does nothing. The document stay unchanged and only contain the original file.  
No error or warning printed in console.

**Expected behaviour**  
We build the 1st document, then merge others in it, and then call the loadDocument() of the instance. The viewer should display all of the doc.

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

**Code snippet**

```javascript
this.wvInstance.CoreControls.createDocument(this.piecesAttachees[0].file).then(async doc => {
            // Handle additional files
            for (const pieceAttachee of this.piecesAttachees.slice(1)) {
                await doc.mergeDocument(pieceAttachee.file);
            }

            this.wvInstance.loadDocument(doc, { fileName: this.piecesAttachees[0]?.file?.name, withCredentials: true });
        });

```

---

<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:** [October 25, 2022, 3:59pm UTC](https://pdfjs.community/t/the-mergedocument-function-does-not-work/2128/3 "2022-10-25T15:59:26Z")

</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:
- [Open a document from Blob](https://pdfjs.express/documentation/basic-operations/open-document/blob)
- [Merge & extract annotation in PDF.js Express](https://pdfjs.express/documentation/annotation/merge-and-extract)
- [Saving a document as a blob](https://pdfjs.express/documentation/basic-operations/save-document/blob)

APIs:
- [UndefinedlayersUpdated](https://pdfjs.express/api/namespaces.list.html#event:layersUpdated__anchor)
- [Core.Document - initOfflineDB()](https://pdfjs.express/api/Core.Document.html#initOfflineDB__anchor)

Forums:
- [Download PDF with annotations](https://pdfjs.community/t/download-pdf-with-annotations/670/1)
- [Two instances of WebViewer were created on the same HTML element ( React App)](https://pdfjs.community/t/two-instances-of-webviewer-were-created-on-the-same-html-element-react-app/679/1)
- [ChunkLoadError: Loading chunk 12 failed](https://pdfjs.community/t/chunkloaderror-loading-chunk-12-failed/1589/1)

  
  

Share how you are using PDF.js Express in your organization you could win a **$500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free**. Learn more [here](https://utm.guru/ueQNw)

---

<div class="post-metadata">

**Author:** ![zserviss](https://avatars.discourse-cdn.com/v4/letter/z/a9a28c/32.png) [@zserviss](https://pdfjs.community/u/zserviss)\
**Post date:** [October 25, 2022, 4:59pm UTC](https://pdfjs.community/t/the-mergedocument-function-does-not-work/2128/4 "2022-10-25T16:59:32Z")

</div>

Hi Ytuzet,

I would recommend to be using version 8.7.0. There is a namespace change from 7 to 8 so it will look a little different.

```javascript
this.wvInstance.Core.createDocument(this.piecesAttachees[0].file).then(async doc => {
            // Handle additional files
            for (const pieceAttachee of this.piecesAttachees.slice(1)) {
                await doc.mergeDocument(pieceAttachee.file);
            }

            this.wvInstance.UI.loadDocument(doc, { fileName: this.piecesAttachees[0]?.file?.name, withCredentials: true });
        });

```

Please try this sample.

Best Regards,  
Zach Serviss  
Web Development Support Engineer  
PDFTron Systems, Inc.

Share how you are using PDF.js Express in your organization you could win a **$500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free**. Learn more [here](https://utm.guru/ueQNw)

---

<div class="post-metadata">

**Author:** ![ytuzet](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/ytuzet/32/1064_2.png) [@ytuzet](https://pdfjs.community/u/ytuzet)\
**Post date:** [October 26, 2022, 2:17pm UTC](https://pdfjs.community/t/the-mergedocument-function-does-not-work/2128/5 "2022-10-26T14:17:20Z")

</div>

Hi zserviss,

We’ve tested your solution with version 8.7.0 and same problem, the function mergeDocument() is being called, but does nothing :

```javascript
const doc = await this.instance.Core.createDocument(file1);
await doc.mergeDocument(file2);
await this.instance.UI.loadDocument(doc, { fileName: 'file.pdf' });

```

We also noticed several other problems with pdfjs (that don’t exist with pdftron) :

- we can’t merge (this issue)
- blurry document
- unopenable document (error message popup)
- unreadable document (opened but truncated character)
- zoom problem

Thanks for your feedback.

Best Regards

---

<div class="post-metadata">

**Author:** ![zserviss](https://avatars.discourse-cdn.com/v4/letter/z/a9a28c/32.png) [@zserviss](https://pdfjs.community/u/zserviss)\
**Post date:** [October 26, 2022, 10:31pm UTC](https://pdfjs.community/t/the-mergedocument-function-does-not-work/2128/6 "2022-10-26T22:31:16Z")

</div>

Hi Ytuzet,

Sorry for the miscommunication, PDF.js Express does not support document manipulation so `mergeDocument` will not work in express.

Please use PDFTron for document manipulation.

Best Regards,  
Zach Serviss  
Web Development Support Engineer  
PDFTron Systems, Inc.

Share how you are using PDF.js Express in your organization you could win a **$500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free**. Learn more [here](https://utm.guru/ueQNw)
