Automatically generate Word document from template

This article guides you through creating a document generation process in Plumsail Documents. By the end, you’ll know how to generate dynamic Word DOCX documents from a template, making your company’s document workflow more efficient.

For this guide, we will focus on a practical example with an invoice. The final generated document will look something like this:

Generated Word DOCX invoice document using the Modern template engine

Let’s start the configuration process from the beginning:

Configure process

First, either register or log in to your Plumsail account.

Create new process

For this example, we’ll use the prepared invoice DOCX template.

During process creation, click Add Process and select Upload a document. Then select the downloaded invoice template.

Create a new DOCX document generation process from Upload a document with the Modern template engine

Enter a Process name and select DOCX as the Output file type.

The Modern template engine is activated by default. Press Create to finish.

Configure process name and DOCX output file type

If you prefer to create your own template, click Add Process and select Start from blank instead.

Create a new DOCX document generation process from blank with the Modern template engine

Configure template

Once the process is created, proceed to configure the template.

There are several template configuration options:

  • Editor: Where you design or upload your template.

  • Settings: Where you define the output format, filename, and process mode.

Editor

The Editor allows you to edit an uploaded template using the Online editor, Upload, or Download options.

Upload a DOCX template to a process using the Modern template engine
Templating syntax

When creating your documents, note that Plumsail templates use a powerful, minimal-syntax approach designed for simplicity.

To understand the full capabilities of the engine, refer to the Modern template engine documentation.

In short, the engine recognizes data fields, or tokens, within double curly {{ }} brackets. These tokens are placeholders where your specified data will be dynamically inserted. Basic examples include {{companyAddress}} or the date token {{@date}}.

But that’s not all! The engine is smart enough to handle more complex scenarios, such as rendering tables from an item list. In our invoice template, we loop through a collection of products using nested tags with a dot operator, like:

  • {{products.name}}, {{products.price}}, and {{products.quantity}} to access specific properties within a product object.

The templating engine identifies the table row containing these product-related tokens and automatically duplicates the row for every object in the input data array, creating a complete table.

Multiple table rows generated from an item list by the Modern template engine

You can learn more about how to structure tables in your templates in the DOCX tables documentation.

Test template

To visualize the document before saving it, click the Test template.

Test template option for previewing a DOCX template with sample data in the Modern template engine

A dialog will appear with an auto-generated form based on the tokens found in your template.

You can always customize this form if needed. Using a JSON file is also possible.

Test template dialog with an automatically generated form for DOCX sample data

Click Test & Preview to open your document in a new tab. Once you are satisfied with the result, press Save.

Switch the process to Production mode to remove Plumsail watermarks from resulting documents.

Switch the process to Production mode to remove Plumsail watermarks

Template settings

After preparing your document template, configure the output filename and file type.

Go to the template settings and configure the following settings:

  • Enter an Output filename for the generated file. Use tokens to include the invoice number in the filename. For example, using Invoice {{@number}} will result in a filename like Invoice 432.

  • Select DOCX as the Output file type.

Settings for configuring a DOCX template process

For more advanced customization, please review our template settings documentation.

You can also add multiple templates to the same process to generate a set of documents in a single run.

Once all settings are configured, click Save.

Delivery

This step defines where your newly generated document will be sent or saved. You can configure multiple delivery options.

For demonstration purposes, we’ll set up an email notification using Zoho Email.

Zoho Mail delivery configuration for generated DOCX documents

Learn more about other available delivery options.

Start process

Your document generation process is now fully configured. The final step, Start process, shows a complete list of possible integrations and triggers.

Integration and trigger options for starting a DOCX document generation process

You can start the process in several ways, including: