Javascript Library for Merging Docx file in NodeJS and Browser Environment.
npm install docx-mergerbash
npm install docx-merger
`
Back to top
$3
Read input files as binary and pass it to the DocxMerger constructor fuction as a array of files.
Then call the save function with first argument as nodebuffer, check the example below.
`javascript
var DocxMerger = require('docx-merger');
var fs = require('fs');
var path = require('path');
var file1 = fs
.readFileSync(path.resolve(__dirname, 'template.docx'), 'binary');
var file2 = fs
.readFileSync(path.resolve(__dirname, 'template1.docx'), 'binary');
var docx = new DocxMerger({},[file1,file2]);
//SAVING THE DOCX FILE
docx.save('nodebuffer',function (data) {
// fs.writeFile("output.zip", data, function(err){/.../});
fs.writeFile("output.docx", data, function(err){/.../});
});
`
Back to top
$3
- Async Load files using jszip-utils and then call the callback in the innermost callback.
- Call the save function wit first argument as blob.
- Better use Promises instead of callbacks.
- Callback causes callback hell issue.
###### Using Callback
`html
`
###### Using Promise
`html
``