0.3.0 • Published 1 year ago

@scholarcy/docx-merger v0.3.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 year ago

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

  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

Known Issues

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

    Back to top