You are currently offline, serving cached version

Usage (nodejs)

Your docx should contain the text: {:footnote foot}

const FootnoteModule = require("docxtemplater-footnote-module");
const fs = require("fs");

const doc = new Docxtemplater(zip, {
    modules: [new FootnoteModule({})],
});
doc.render({ foot: "The text of the footnote" });

const buffer = doc.getZip().generate({
    type: "nodebuffer",
    compression: "DEFLATE",
});

fs.writeFile("test.docx", buffer);

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

Bold/Italic

It is possible to write your footnotes with bold/italic or other styles :

Footnote styled
Footnotes with bold and italic style

To achieve this, use following code :

const doc = new Docxtemplater(zip, {
    modules: [
        new FootnoteModule({
            raw: true,
        }),
    ],
});
doc.render({
    foot: `<w:r>
    <w:rPr><w:b/></w:rPr>
    <w:t xml:space="preserve">Albert Einstein – Biography </w:t>
    </w:r>
    <w:r>
    <w:rPr><w:i/></w:rPr>
    <w:t>. Nobel Foundation. Archived from the original on 6 March 2007. Retrieved 7 March 2007.</w:t>
    </w:r>
    `,
});

Customization

It is possible to customize how footnotes look like with the refProperties option.

For example, to have the numbers in the footnotes section written in superscript, you can do :

const doc = new Docxtemplater(zip, {
    modules: [
        new FootnoteModule({
            refProperties: '<w:vertAlign w:val="superscript"/>',
        }),
    ],
});
doc.render(/* data */);

It is possible to use periods in the footnotes by using the following :

const doc = new Docxtemplater(zip, {
    modules: [
        new FootnoteModule({
            refRun: '<w:r><w:t xml:space="preserve">. </w:t></w:r>',
        }),
    ],
});
doc.render(/* data */);

It is possible to change the paragraphProperties of the footnote paragraphs, for example the amount of space after a paragraph or the indent :

const doc = new Docxtemplater(zip, {
    modules: [
        new FootnoteModule({
            paragraphProperties:
                '<w:spacing w:after="200"/><w:ind w:left="0" w:hanging="-480"/>',
        }),
    ],
});
doc.render(/* data */);

It also is possible to customize the run properties of the text of the footnote :

const doc = new Docxtemplater(zip, {
    modules: [
        new FootnoteModule({
            runProperties:
                '<w:sz w:val="16"/><w:szCs w:val="16"/>',
        }),
    ],
});
doc.render(/* data */);

Building in the browser

You can build a release for the browser with the following commands

npm install
npm run preversion

You will have build/footnotemodule.js.

CHANGELOG

3.4.5

Upgrade module to use NodeNext moduleResolution setting. See explanation here

3.4.4

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

3.4.3

Upgrade to correctly pass in fileType, contentType, … to postparsed

Makes it compatible with docxtemplater 3.40.1

3.4.2

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

3.4.1

Detect the correct style to be used for Footnotes more accurately.

3.4.0

Add new options to customize the appearance of footnotes :

refRun, paragraphProperties, runProperties

3.3.1

Stop creating word/_rels/settings.xml.rels when using docxtemplater 3.28.6 or above

3.3.0

Make module compatible with docxtemplater@3.28.0. Please make sure to update docxtemplater to 3.28.0 at the same time you update this module. The internal change made is the use of the new matchers API which fixes bugs that were triggered depending on the order of the modules that are attached to the instance. Now the order of the modules should not matter as expected.

3.2.6

Bugfix issue when using docxtemplater 3.23.0:

doc.setTags is not a function

3.2.5

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

3.2.4

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

3.2.3

Add typescript definitions for public API

3.2.2

Move webpack from dependency to devDependency (which triggered an error during installation on node version 10)

3.2.1

Internal change to allow to match tags with non-breaking space.

When entering Ctrl+Shift+Space, a "non-breaking" space is created.

When using a non-breaking space in the tag {:footnote data}, the tag would not be replaced correctly.

3.2.0

If you use docxtemplater 3.20.0 or later, you have to upgrade the footnotes module to this version.

This is because of an internal change in the docxtemplater module that also affects the footnotes module.

3.1.4

Add support to template existing footnotes, for example if a footnote contains : Hello {name} , it will be replaced by Hello Edgar if the data is {name: "Edgar"}

3.1.3

Small bugfix related to change in "docxtemplater@3.17.2", you need to upgrade to "docxtemplater@3.17.3" and this version to avoid a possible corruption in settings.xml

3.1.2

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

3.1.1

Bugfix : Do not fail with "Cannot read property 'toString' of undefined" when passing no data

3.1.0

  • Add support for {raw: true} option to pass data as runs instead of as texts

  • Fix bug (escape) when data contains >, < or other XML characters

3.0.7

  • Update browser build to use XMLSerializer instead of xmldom

  • Use requiredAPIVersion

3.0.6

  • Move docxtemplater from devDependencies to dependencies

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

3.0.4

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

3.0.3

Make it possible to style footnotes with option refProperties

3.0.2

Mark package as private in package.json

3.0.1

It now works even if some footnotes already exist (if word/footnotes.xml exists)

3.0.0

Initial release.

Talk with sales Contact us