Generate PDF from Word templates with the data from Dynamics 365 CRM

This article shows how to generate documents such as PDF (including fillable PDF), Word, Excel, PowerPoint, and HTML from document templates with data from Dynamics 365 CRM. Our approach allows you to create documents, send them by email, collect e-signatures, and store and deliver them across your favorite apps in automated flows. This approach will help you to overcome Dynamics 365 limitations, such as:

  • inability to export generated documents as PDFs;

  • inability to send created PDFs directly by email without having to download them;

  • the known issue with creating templates in Word;

  • inability to use templates in a particular environment if they were downloaded from another environment;

As you can see, built-in Dynamics 365 CRM functionality does not allow users to implement usable PDF document generation. Our method represents how to set document automation practically. In our example, we’ll generate customized PDF invoices from Word templates for selected orders in Dynamics 365 CRM and send the resulting document by email.

Start document generation process action

We will use Power Automate (Microsoft Flow) and the Plumsail Documents connector. Here is the flow:

Generate custom invoices from D365 orders flow

Here is the step-by-step instruction:

Configure process

Before you proceed to create the flow, you need to create and configure the process which will generate PDF documents from a Word template.

To start, register or login to your Plumsail account.

Create new process

Click the Add process button and start from a ready template, or click “Start from blank” if you have your document template design.

Add process button

Pick the document design from our ready-to-do templates, or choose the document format if you started from blank in the previous step. As you see in the screenshot below, we choose the simple invoice template for our example.

Choose template

Name the process and go to the next step.

Name process

Configure template

You clicked the Next button and found yourself in the first step of the process - Configure template.

It includes two substeps:

  • Editor;

  • Settings.

In Editor, you can compose the template from scratch or upload a pre-made one. It’s also possible to modify the current template online if you wish to change the logo or adjust it to your use case.

Edit template

Templating syntax

You can use the documents you already have but they should meet the requirements for the Plumsail Documents Word templates. There is nothing complex here - everything between such curly {{ }} brackets is variables where the templating engine will apply your specified data. These variables, also known as tokens, are placeholders for the data merged from other systems into a document template.

The syntax is easy yet powerful - it supports lists, tables, charts, and many more.

Test template

You can check how the resulting file looks if you click Test template.

In our example, we see a form with fields that correspond to tokens (variables) from our invoice Word template. Plumsail Documents engine creates a default form with fields related to tokens for every document template. You can embed this web form into your site or share a link with somebody to fill it out manually. You can adjust the default form and customize the design. Find more information in the documentation.

We enter some data into the fields to test our Word template.

Test template


This is testing. We will pass data from Dynamics 365 CRM to the process. See the Start process section.

Click Save & Next to proceed to Settings. Here you’ll see the following parameters.

Template mode. By default, it’s Testing, which means that runs of this process are free of charge for you, but the resulting documents will have a Plumsail watermark. To remove it, switch the mode to Active.

Output filename. To personalize it, use tokens from the template. They will work the same way as for the template. For example, we have {{customer}} token. The real customer’s name will replace this token, and we’ll get the file “Invoice for Cacilia Viera”. It will change dynamically according to specified data.

Output type. The default is the same as the template’s format. It’s possible to select PDF.


You can protect your final PDF document with a watermark, by setting a password, or disabling some actions.

Test template. Once you’ve customized all the settings, you can test the template to see the result as we did it previously.

Configure template settings

When everything is done here, click Save & Next to set up deliveries.


It’s possible to add as many deliveries as you need. For instance, you could save the resulting invoice to your SharePoint library or OneDrive folder, then send as an e-mail attachment to the customer. Check out the full list of available deliveries.

We’ll add an Outlook delivery for demonstrating purpose. It will deliver the invoice completed with Dynamics 365 data to the customer.

We put token {{email}} as a recipient’s email address. So, it will adjust dynamically every time according to the specified data. The process will pull it from Dynamics 365 CRM. Also, we filled in the subject and email body.

Outlook delivery

Next, we’ll start the process from Power Automate.

Create flow

We’ve decided to trigger the flow for a selected record (order) in Dynamics 365 CRM. In your case, it can be a different trigger related to your events in CRM.

For that, we use Microsoft Dataverse (legacy) - When a row is selected.

When a row is selected

The environment parameter is Default, the table name is Orders:

When a record is selected trigger

Besides, we added an input date to use it in the template.

The trigger is done, the next step is - Get a row by ID.

Get a row by ID

This action is from Microsoft Dataverse, not legacy. We need to assign it to pull the details on the order products and their properties as the trigger alone won’t provide us with this data.

Get order
  • Table name - select Orders.

  • Row ID - select Order from the dynamic content of the trigger output.

  • Expand Query - use this string: $expand=order_details,customerid_contact($expand=parentcustomerid_account). It’s important to customize the OData query. Otherwise, the action will return the same data as the trigger - without information about products related to the order.

Now save the flow and launch a test run. After it ran successfully, copy JSON data from outputs of the current action.

Get order outputs

We will need it in the next action - Parse JSON.

Parse JSON

We assign this action to pull out data on products separately from other data we don’t need.

Parse JSON action
  • Content - select Body from the dynamic content of Get a record outputs.

  • Schema - click Generate from sample and paste JSON you’ve copied earlier into the dialog.

We’re moving to the last step - Start document generation process.

Start document generation process

This is the action from the Plumsail Documents connector for Power Automate - it will start the process we’ve configured.

If it’s your first time using Plumsail Documents actions in flow, be ready to create a new connection and provide Power Automate with Connection name and API Key:

Create Documents connection

You can type any name for the connection. For example, Plumsail Documents.

Then create an API key in your Plumsail Account page, copy and paste it to API Key field.

The Start Document generation process action has two parameters:

  • Process name - select from the dropdown.

  • Template data - specify it with dynamic content from Dynamics CRM. To specify products array, insert order_details, customer - fullname, company - name. It is all the dynamic content of the Parse JSON output. No need to wrap it with quotation marks.

Start document generation process

That’s it. To launch the flow, select an order you need to generate an invoice for, in the top navigation menu go to Flow and choose the flow:

Run flow

Once the flow ran successfully, the customer receives a personalized email with the invoice attached:

Invoice created from Dynamics 365 CRM

Use ready invoices in flow

It’s possible to continue working with the generated invoices from Dynamics 365 further in flow. For example, you can send them for approval. Just add the result file returned by Start document generation process action as an attachment:

Send Dynamics 365 invoice for approval


Now you know how to generate cusomized PDF invoices with logos from Word templates with the data from Microsoft Dynamics 365 CRM. Utilize this approach to create any custom documents from any entities in Dynamics 365 CRM.