Create PDF Documents from Data in Power Automate

In this post I will look at how to create PDF documents from data.

Use Cases

In the example that I’m using in this post I will generate a quotation document that takes data from my Dynamics 365 system. But there are so many more use cases for PDF document that take data from any kind of data source.

Your data may live in SharePoint lists, or maybe SQL or maybe even Dataverse it all doesn’t really matter. The aim will all be the same take some data and put it into a nice looking document that is ready to impress the reader.

In my case I got a design delivered in a word document and needed to generate a PDF from a Model Driven app.

now I could use the document generation within Dynamics but I quite quickly found myself going through hoops to make things work. So I thought, I could create a flow.

So straight from my opportunity in Dynamics 365 I can generate a quote that is emailed to me in PDF format ready to send to my client.

Create PDF documents from data in Power Automate

Data

In my case I’m going to use the data in Dynamics 365 and generate the html from that.

First steps first. I created the html for my document. This is where you will start to look at the document and recognize that you have pages with a header and a footer and in the footer there is a page number.

If you considered using a flow like this then you will find quote quickly that the OneDrive PDF conversion isn’t up to the job

A couple of the issues that I ran into were:

  1. Header and Footer support
  2. Tables next to each other is really painful
  3. Background colours on rows in tables
  4. And quite a few more issues.

So I started to look at other options.

Encodian

The connector that I looked into to generate the PDFs is called Encodian. In this post I will give a bit more information on how to use this great connector. But it isn’t just the connector that is great. During my trials i tested their support team and their support is second to none.

I’m going to start with the generation of the HTML. I’m not going to go into details here as every document will be different. If you need help with generation the html fell free to contact me and I can help you build the flows to do this.

First of all you will need to generate the main html for the page. This is all of the pages without the headers and the footers.

So I initialized a variable that hold my html.

Create PDF documents from data in Power Automate

Then I add the html for each element within my document. it is useful to add some comments in your html so that you can recognize the different parts of your document.

Create PDF documents from data in Power Automate

Now that we have the html ready, we can Create PDF documents from the html.

Create PDF documents from HTML

The flow that I created uses a few actions from the Encodian connector to create PDF documents. First we will need to convert the HTML to PDF using the Convert HTML to PDF action.

Create PDF documents from data in Power Automate

Now we will need to add the header and the footer. There is only one action available for this. The Add HTML Header or Footer will ask you to select the location. this can be Footer or Header but also both. When you select both your header and footer will be the same. I’m not sure when you would do this, but I’m sure there will be some use case for that.

So just construct the HTML that you want to appear on all pages and your PDF will have the footer and the header that you want, making your document look good.

Create PDF documents from data in Power Automate

Now we have a header and a footer but no page numbers yet. This however is the easy part. The Add page numbers lets you add a page number to each page in whatever format you might need. In page case I wanted the page number of total pages format.

Create PDF documents from data in Power Automate

Then the result quite quickly looked like this.

Find more great content here!

Reference:

Veenstra, P. (2021). Create PDF documents from data in Power Automate. Available at: https://sharepains.com/2021/02/18/create-pdf-documents-data-power-automate/ [Accessed: 3rd March 2021].

Find more great Power Platform content here.

Share this on...

Rate this Post:

Share: