Skip to content

lucasretamoso/docx-merger

 
 

Repository files navigation

Docx-merger

Javascript Library for Merging Docx files. This is a fork of https://github.com/scholarcy/docx-merger with a fix to integrate it with html-to-docx.

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

  1. Installation
  2. Usage Nodejs
  3. Usage Browser
  4. TODO
  5. Known Issues

Installation

npm install @scholarcy/docx-merger

Back to top

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);
})()

Back to top

TODO

  • CLI Support
  • Unit Tests
  • ES6 Conversion

Back to top

Known Issues

  • Microsoft Word in windows Shows some error due to numbering.

Back to top

About

Javascript Library for Merging Docx file in NodeJS and Browser Environment.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%