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.

Word document to create a document for

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

Create PDF documents from data in Power Automate

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

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.

Create PDF documents from data in Power Automate


Discover more from SharePains by Microsoft MVP Pieter Veenstra

Subscribe to get the latest posts sent to your email.

8 thoughts on “Create PDF documents from data in Power Automate”
  1. Hi, I want to create a flow in which the flow will read the data from a source it can be Excel or SharePoint List or SQL (on prem)
    and then it will have employee information there and then the email will be sent to those employees according to their status and also send them an email attachment too as a PDF.
    can you please help me with it? as I am using standard connectors of one drive create file and then using in send email (v2) action.
    and my html is not looking good in PDF attachment..

  2. Well, I understand that, but is Encodian free? or the client have to buy the subscription? for like we have to send 5000 – 8,000 emails with PDF attachments to the employees.

    1. You would need to buy an Encodian subscription. It is a standard connector so no premium Power Automate.

      It is all a choice between good looking pdfs nd looking professional or poor looking PDFs and looking less professional. It is up to the client.

  3. Ok, I understand but I need help with the HTML content as I have written an HTML code its showing good over (Outlook Online) but not same on (Outlook Client) the HTML is looking very bad there.. what should I do?

    Please help !

  4. well, how can we connect? well I have an HTML and its showing on Email body and when I converted that HTML into PDF using convert file and sent as an attachment the HTML table alignment are really bad and not same as shown in HTML (which they are in middle)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from SharePains by Microsoft MVP Pieter Veenstra

Subscribe now to keep reading and get access to the full archive.

Continue reading