You are currently offline, serving cached version

This module doesn't expose tags, but it makes it possible to do some operations on the docx itself.

The META module currently can :

  • Make a document readonly
  • Add a text watermark
  • Update the margins

Installation

You will need docxtemplater v3: npm install docxtemplater

Install this module with npm install --save "$url"

Usage

To use this module, do your operations after compile, before render :

Readonly

const DocxtemplaterMetaModule = require("docxtemplater-meta-module");
const metaModule = new DocxtemplaterMetaModule();
const doc = new Docxtemplater(zip, {
    modules: [metaModule],
});
doc.setData(data);
metaModule.readonly();
doc.render();
const buffer = doc.getZip().generate({ type: "nodebuffer" });

Watermark

const DocxtemplaterMetaModule = require("docxtemplater-meta-module");
const metaModule = new DocxtemplaterMetaModule();
const doc = new Docxtemplater(zip, {
    modules: [metaModule],
});
doc.setData(data);
metaModule.addTextWatermark("DRAFT", {
    diagonal: true,
});
doc.render();
const buffer = doc.getZip().generate({ type: "nodebuffer" });

Margins

const DocxtemplaterMetaModule = require("docxtemplater-meta-module");
const metaModule = new DocxtemplaterMetaModule();
const doc = new Docxtemplater(zip, {
    modules: [metaModule],
});
doc.setData(data);
// Margins are in inches, and apply to all pages
metaModule.setMargins({
    top: 0.5,
    left: 0.8,
    right: 1.2,
    bottom: 1,
});
doc.render();
const buffer = doc.getZip().generate({ type: "nodebuffer" });

Hyperlink Base

const DocxtemplaterMetaModule = require("docxtemplater-meta-module");
const metaModule = new DocxtemplaterMetaModule();
const doc = new Docxtemplater(zip, {
    modules: [metaModule],
});
doc.setData(data);
const baseLink = "https://github.com/facebook/react";
metaModule.setHyperlinkBase(baseLink);
doc.render();
const buffer = doc.getZip().generate({ type: "nodebuffer" });

After installing the module, you can use a working demo by running node sample.js.

CHANGELOG

3.2.6

Use @xmldom/xmldom instead of xmldom, see this github issue

3.2.5

Generate files in built with correct filename In previous versions, the filename was always build/docxtemplater.js. Now the filename is error-location-module.js The .min.js file is also created now.

3.2.4

Add typescript definitions for public API

3.2.3

Add support for setting hyperlink base, for example :

const baseLink = "https://github.com/facebook/react";
metaModule.setHyperlinkBase(baseLink);

3.2.2

Add support for setting header/footer margins, for example :

metaModule.setMargins({
    left: 0.1,
    right: 0.1,
    top: 0.5,
    bottom: 0.5,
    header: 0.05,
    footer: 0.05,
});

3.2.1

Declare supportedFileTypes, which allows to use this module with the new docxtemplater constructor which was introduced in docxtemplater 3.17.

3.2.0

Add API to change margins

3.1.0

Add API to add text watermark

3.0.2

  • Update browser build to use XMLSerializer instead of xmldom

  • Use requiredAPIVersion

3.0.1

  • Move docxtemplater from devDependencies to dependencies

Explanation : On some versions of npm (notably 5.8.0), when having a package containing docxtemplater-meta-module, the installation will generate a tree of node_modules that puts the module on a level where it has no access to docxtemplater. By explicitly asking it as a dependency, this issue is avoided.

3.0.0

Initial release