Note
There is a simpler way to create Word and PDF documents from a template and use the result in Power Automate if needed.
This article demonstrates how to generate PDF document from a DOCX template with the help of Power Automate (Microsoft Flow).
We will firstly generate DOCX document from a template and convert it to PDF. In this article, we will generate PDF invoice based on some data. This is how our final PDF file looks:
Our template and result document have to be stored somewhere. Power Automate (Microsoft Flow) has a lot of connectors for different systems. Here are just a few of them:
SharePoint
Salesforce
Box
OneDrive
Google Drive
Dropbox
SFTP
File System
You can store your source file anywhere. In this example, we will store our documents in SharePoint. Our Flow will get a template from a SharePoint document library, generate a new document based on this template and on some data. The resulting document will be stored back to SharePoint document library.
Now we need to create a Power Automate (Microsoft Flow) that will get the template from the SharePoint document library, apply data to this template, convert a document to PDF and save it back to the document library. This is how complete flow looks:
Here is the step by step description for the flow.
You can actually pick any trigger. For example, you can start Flow on file creation in a SharePoint document library. We use “Manually trigger a flow” trigger here to simplify the Flow.
This action gets file content of the specified file from a SharePoint document library. You just specify SharePoint site URL and path to your file. We use this action to read .docx template.
You can use any other connector to get files from your system.
This is an action from Plumsail Documents connector.
There are two parameters:
DOCX template file
Template data
Document output type
In the first parameter ‘DOCX template file’ we specified file content of a template from the output of the previous action. Use this link to download it.
Read Create DOCX from template article to understand how the templating engine works.
In the second parameter, we specified data to apply to the template in JSON format. This is information about a sample employee. You can actually request this information from an external system with the help of another Power Automate (Microsoft Flow) action.
This is our sample data:
{
"invoiceNumber": "432",
"company": {
"email": "sales@sample.com",
"address": "3 Main St.New York NY 97203 USA",
"phone": "202-555-0131"
},
"date": "2018-05-21",
"items": [
{
"product": {
"name": "Monitor",
"price": 99
},
"quantity": 10,
"cost": 990
},
{
"product": {
"name": "Stepler",
"price": 12.44
},
"quantity": 1000,
"cost": 12440
},
{
"product": {
"name": "Fridge",
"price": 4219.99
},
"quantity": 1,
"cost": 4219.99
},
{
"product": {
"name": "Microwave",
"price": 99.99
},
"quantity": 5,
"cost": 499.95
},
{
"product": {
"name": "Pen",
"price": 7.23
},
"quantity": 100,
"cost": 723
}
],
"total": 18872.94
}
In the third parameter, we select PDF output type of the resulting file.
Learn more information Create DOCX document from template action.