docx-merger icon indicating copy to clipboard operation
docx-merger copied to clipboard

Word shows "Word found unreadable content" error

Open sundowatch opened this issue 5 years ago • 7 comments

I'm trying to merge docx files via docx-merger library. Everything is good, except of Microsoft Word's "Word found unreadable content in output.docx. Do you want to recover the contents of this document? If you trust the source of this document, click Yes." message. It opens the document when click to yes, but not the output file, just a buffer.

Here is my code:

const docxMerger = require('docx-merger');
fs.readdir('input/', (err, bufferFiles) => {
    var bufferFilesArr = [];
    bufferFiles.forEach(bufferFile => {
    var file = fs.readFileSync(path.resolve('app/temps/buffer',bufferFile), 'binary');
    bufferFilesArr.push(file);
    });
    var mergedDocx = new docxMerger({}, bufferFilesArr);

    mergedDocx.save('nodebuffer', function(data){{
    fs.writeFileSync(path.resolve('output','output.docx'), data, 'utf8',function(err){
        //callback
    });
    }});
});

I'm trying here to merge docx files which are in the input folder.

It merges all of them, but I can not open file without this message.

sundowatch avatar Sep 21 '19 16:09 sundowatch

any updates here?

brunomazzardo avatar Oct 08 '19 17:10 brunomazzardo

I'm looking all around the web. But I can't find any solution for that

sundowatch avatar Oct 08 '19 17:10 sundowatch

I would like a solution to this as well

adriangith avatar Mar 24 '20 05:03 adriangith

A bit late but I experience this issue when merging documents that include different headers and footers. It appears that the library doesn't really know how to merge documents with different headers/footers because you technically should have a single. header/footer per document or your document will need sections to have different headers/footers.

Looking at the source code, it doesn't really appear that the headers/footers are actually managed in any way, so that could potentially be an issue. Merging documents without any headers/footers seems to work fine though.

It is also worth noting that if the first document in your array buffer doesn't have a header/footer, but the following documents do, then you will get a corrupt word file because docxmerger will not try to merge a file that's not there at all. The following documents will then cause a corrupt word file because the document.xml will contain references to header/footer xml files that were never merged into the final doc.

chrisdlim avatar Aug 24 '20 18:08 chrisdlim

same issue encountered..

sheerinZ avatar Jul 26 '21 08:07 sheerinZ

Same issue here :(

SimoColna avatar Aug 18 '22 10:08 SimoColna

since the package has not been updated for more than 7 years and the package has some bugs regarding "corrupt" Word files, I created my own package. This package also has TypeScript support. See here: https://www.npmjs.com/package/@spfxappdev/docxmerger

I'm not sure if it will help you @SimoColna @sheerinZ @adriangith @sundowatch @brunomazzardo

SPFxAppDev avatar Feb 07 '24 22:02 SPFxAppDev