This module exposes a tag to add a footnote to the document
This module is available as part of the docxtemplater PRO plan.
You will need docxtemplater npm install docxtemplater
Install this module with npm install --save "$url"
Your docx should contain the text: {:footnote foot}
var FootnoteModule = require("docxtemplater-footnote-module");
var footnoteModule = new FootnoteModule({});
var zip = new PizZip(content);
var doc = new Docxtemplater(zip, {
modules: [footnoteModule],
});
doc.setData({ foot: "The text of the footnote" }).render();
var 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
.
It is possible to write your footnotes with bold/italic or other styles :
To do it , use following code :
var footnoteModule = new FootnoteModule({
raw: true,
});
doc.setData({
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>
`,
});
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 :
var footnoteModule = new FootnoteModule({
refProperties: '<w:vertAlign w:val="superscript"/>',
});
You can build a release for the browser with the following commands
npm install
npm run preversion
You will have build/footnotemodule.js.
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.
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"}
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
Declare supportedFileTypes, which allows to use this module with the new docxtemplater constructor which was introduced in docxtemplater 3.17.
Bugfix : Do not fail with "Cannot read property 'toString' of undefined" when passing no data
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
Update browser build to use XMLSerializer instead of xmldom
Use requiredAPIVersion
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.
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 meta context argument to custom parser with information about the tag for each types of tags
Make it possible to style footnotes with option refProperties
Mark package as private in package.json
It now works even if some footnotes already exist (if word/footnotes.xml exists)
Initial release.
Edgar Hipp