Demo
Readme
Changelog
Releases RSS Feed
Compatibility : nodejs and browser

Summary (version 3.2.1) Buy qrcode module

This module makes it possible to replace an image by an other image

This module is available as part of the docxtemplater ENTREPRISE plan.

README

QrCode Module

This module exposes a tag to include qrCode. The qrcode of the pages are parsed, then they are replaced with with the getImage function.

Docxtemplater will keep all the styling that you put on your qrcode (shades, effects, size, …).

Installation:

You will need docxtemplater v3: npm install docxtemplater

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

Usage

Your docx should contain an image that contains a qrcode text. You can use a http://qrcode.kaywa.com/ in Text mode to generate your qrcodes.

The file has to be a JPG/BMP/PNG file, since the image parser that we use can only read these formats (TIFF format is not handled). If your qrcode is not replaced, it is possible that it is because your image was saved as TIFF.

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

Options

The qrcode module takes as an argument the getImage function, which should return the image depending on the resolved tag value.

const qrCodeModule = new QrCodeModule({
    getImage: function(tag) {
        return fs.readFileSync(path.resolve(__dirname, "..", "images", tag));
    },
});

The qrcode module takes as an argument the autoDelimiters boolean (false by default). When autoDelimiters is set to true, instead of encoding "{image}" in your qrcode, you can just encode "image".

Async support

It is possible to get images asynchronously by returning a Promise in the getImage function and use the docxtemplater async api : http://docxtemplater.readthedocs.io/en/latest/async.html

Webpack support

To make this module work well in webpack, you have to declare the following in your webpack.config.js (in the module.exports):

plugins: [
        new webpack.DefinePlugin({
                "process.env": {
                        ENV: JSON.stringify("BROWSER"),
                },
        }),
],

CHANGELOG

3.2.1

  • Update browser build to use XMLSerializer instead of xmldom

  • Use requiredAPIVersion

3.2.0

  • Update jsqr to 1.1.1

  • Fix bug docPrId duplicated

3.1.6

  • Move docxtemplater from devDependencies to dependencies

Explanation : On some versions of npm (notably 5.8.0), when having a package containing docxtemplater-qrcode-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.1.5

  • Make module compatible with docxtemplater version 3.5 and below.

Explanation : Recently, the scopemananger API (internal API) has changed, this new version of the footnotes module makes the module work with both versions newer than 3.6 and older than 3.6 of docxtemplater.

  • Add autoDelimiters option

3.1.4

Add meta context argument to custom parser with information about the tag for each types of tags

3.1.3

  • Add async support (by returning a Promise in the getImage function).

3.1.2

Accept getImage as option to have similar API as the image module.

loader is still accepted, but will be deprecated in future major version

3.1.1

  • Correctly handle failed qrcode parsing

3.1.0

  • Replace qrcode-engine to handle more "versions" of the qrcode specification

3.0.5

  • Do not fail if one image cannot be parsed (EMF files for example)

3.0.4

  • Make it possible to have object in data values, for example :

the qrcode could be decoded to {parameters} and the data is :

{
    "parameters": {"path": "path_to_file.png"}
}

and the loader function will now be called with :

loader({"path": "path_to_file.png"})

before this release, it was called with "" by mistake.

3.0.3

  • Add browserified and minified bundles

3.0.2

  • Use Jimp dependency to allow installation without Python

3.0.1

  • Bugfix when qrCode empty
  • Works with slides modules
  • Works with pptx
  • Works with multiple smartarts

3.0.0

Initial release

Edgar Hipp

I'm the creator of docxtemplater. I work on making docxtemplater great since 2013.