This project provides a library usable in the browser with advanced features for docxtemplater (including all modules).
It allows a user to load a template file, fill it with predefined data, and then save the generated document.
{%logo} syntaxOnce you've downloaded the code, you can have a look at our demo by opening index.html in a browser.
To use the software, simply add a single script tag like this :
<script src="built/docxtemplater.umd.js"></script>
Retrieve the docGeneration Object:
/* eslint-disable-next-line no-unused-vars */
const dg = window.docGeneration;
docGeneration object is accessed from the window object, which is provided globally by the library.Load the DOCX Template:
/* eslint-disable-next-line no-undef,no-unused-vars */
const content = await dg.loadFile(
"https://docxtemplater.com/ang-example.docx"
);
Define the Data to Inject:
/* eslint-disable-next-line no-unused-vars */
const data = {
first_name: "John",
last_name: "Doe",
phone: "John",
organization: {
companyName: "Acme Ecorp",
},
description: "The long description",
};
Generate the Document:
const configuration = {};
/* eslint-disable-next-line no-undef,no-unused-vars */
const { blob, errorLocation } = await dg.generateDocument(
/* eslint-disable-next-line no-undef */
content,
data,
configuration
);
generateDocument function processes the template and applies the provided data.errorLocation will be true.The configuration object has the same configuration keys as the docker version.
Save the Output:
/* eslint-disable-next-line no-undef */
if (errorLocation) {
/* eslint-disable-next-line no-undef */
dg.saveAs(blob, "template-with-errors-comments.docx");
} else {
/* eslint-disable-next-line no-undef */
dg.saveAs(blob, "output.docx");
}
output.docx.It is possible to change the delimiters by using the following code :
const configuration = {};
/* eslint-disable-next-line no-undef,no-unused-vars */
const { blob, errorLocation } = await dg.generateDocument(
/* eslint-disable-next-line no-undef */
content,
data,
configuration,
{
query: { delimiters: "[[ ]]" },
}
);
Full license information can be found here
Add additional security measures (previous versions were already secure thanks to the CSP option which was set to true by default)
Bugfix error that would always happen with 3.2.0 :
This is now fixed
Initial version