You are currently offline, serving cached version

Summary

This module exposes a tag to replace a qrCode image in your template into any kind of image. 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, …).

The following :

Qrcode
Qrcode containing the static text {company.logo}

with following data :

doc.renderAsync({
    company: {
        logo: "acme.png",
    },
});

Will render :

Acme logo
Acme logo

Usage

Your docx should contain an image that contains a qrcode text. You can use The Qrcode Generator in Text mode to generate your qrcodes (you need to click on the "free text" button first).

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 = require("docxtemplater-qrcode-module");
const fs = require("fs");
const path = require("path");

const qrCodeModule = new QrCodeModule({
    getImage(value) {
        return fs.readFileSync(
            path.resolve(__dirname, "..", "images", value)
        );
    },
});
const doc = new Docxtemplater(zip, { modules: [qrCodeModule] });
doc.render(data);

The qrcode module constructor 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.

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):

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

CHANGELOG

3.4.9

Upgrade to use @jimp/custom to avoid pulling many unused dependencies

3.4.8

Upgrade module to use NodeNext moduleResolution setting. See explanation here

3.4.7

When using the inspectModule to getAllTags, avoid showing "undefined" key for qrcode tags.

Requires docxtemplater 3.42.1 or higher

3.4.6

Allow to insert emf images (use correct content-type of image/x-emf)

3.4.5

Fix bug when using renderAsync and parser compilation fails : the error should now be shown inside a multierror. To to this, we know use sm.getValueAsync in resolve instead of sm.getValue

3.4.4

Bugfix to set or get xml attributes correctly, even when using tabs instead of spaces in tags attributes

3.4.3

Set module.priority in order to have no more issues related to module ordering

3.4.2

Add module.clone() internal to make module work well with subsegment module

3.4.1

Add endLindex to qrcode part.

Fixes issue of disappearing images when used together with subsegment module

3.4.0

This version requires docxtemplater@3.35.0 or more.

Bugfix : When having an image inside a textbox that also had some text, the tags that are in the textbox were not correctly replaced.

This happened both if the image was a real qrcode or if it was a standard image tag.

The bug meant that the tags were replaced like this :

{first_name} {last_name}

With the data : doc.render({first_name: "John", last_name: "Doe"});

Was replaced by this :

first_name last_name

3.3.0

Rename loader function to getImage

The loader function can no more be used now.

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 build/qrcode-module.js The .min.js file is also created now.

3.2.4

Add typescript definitions for public API

3.2.3

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

3.2.2

  • Bugfix for slide-module + Performance : Analyze only files that can contain images. WIth slides-module v3.2.2, and with qrcode-module v3.2.1 or below, some unintended "slideNotes.rels.xml" were created

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 qrcode 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

Talk with sales Contact us