@scholarcy/docx-merger
v0.3.0
Published
Javascript Library for Merging Docx file in NodeJS and Browser Environment.
Downloads
660
Readme
Docx-merger
Javascript Library for Merging Docx files. This is a fork of https://github.com/apurvaojas/docx-merge with updated dependencies.
It's only been tested with NodeJS but according to the original authors it should work in the browser too.
The fork has replaced webpack with esbuild as the build tool, and yarn for npm.
Purpose
To merge docx file using javascript which has rich contents.
The Library Preserves the Styles, Tables, Images, Bullets and Numberings of input files.
Table of Contents
Installation
npm install @scholarcy/docx-merger
Usage in Nodejs
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.
const DocxMerger = require('./../src/index');
const fs = require('fs');
const path = require('path');
(async () => {
const file1 = fs.readFileSync(path.resolve(__dirname, 'template.docx'), 'binary');
const file2 = fs.readFileSync(path.resolve(__dirname, 'template1.docx'), 'binary');
const docx = new DocxMerger();
await docx.initialize({},[file1,file2]);
//SAVING THE DOCX FILE
const data = await docx.save('nodebuffer');
await fs.writeFile("output.zip", data);
await fs.writeFile("output.docx", data);
})()
TODO
- CLI Support
- Unit Tests
- ES6 Conversion
Known Issues
- Microsoft Word in windows Shows some error due to numbering.