Create a PDF file from a SharePoint list item using the no-code Microsoft Power Automate Platform.
In March 2018, Microsoft announced the Microsoft Power Platform. According to Microsoft, the world of business applications is changing. It is a so-called no / low-code platform that anyone with knowledge of Excel and PowerPoint can use to create business applications.
But is this really the whole story? Is the Microsoft Power Platform always adequate for every business solution or are there situations in which it is best to combine the Power Platform with a low-code solution?
This video shows the result of the conversion we are going to create, so lets start some PowerAutomate!
In order to convert a SharePoint list item into a PDF document we first need to convert it into a HTML document. By using a HTML template we convert the SharePoint list-item into a HTML document that is then stored on OneDrive. This step is needed because we want to use an existing PowerAutomate action to convert the HTML document to PDF. Once we created the PDF we can store it back into a SharePoint document library.
First create a SharePoint custom list called ‘ConvertToPDF’. Add two ‘single-line of text’ columns: ‘ExampleColumnOne’ and ‘ExampleColumnTwo’.
Next create a text file called ’template.html’ with the following content and upload it to the ‘Documents’ library in SharePoint.
Content of the HTML template.
1<html>
2 <head>
3 <meta name="generator" content="Microsoft Flow">
4 <title>Convert SharePoint List items to PDF files</title>
5 </head>
6 <body>
7 <p>{ExampleColumnOne}</p>
8 <p>{ExampleColumnTwo}</p>
9 </body>
10</html>
Please notice that the template contains two placeholders {ExampleColumnOne} and {ExampleColumnTwo}. Step 5 will replace these placeholders with real data.
Open PowerAutomate in your Office365 subscription and create a new Flow, select ‘Instant-from blank’.
Configure the steps as listed below (of course your site address will be different)
This is the most tricky step, since we need to replace the contents of the HTML template with data from the list-item. For this we use a compose step and the ‘replace()’ function.
So first add two compose actions:
And type in the replace() function. The first argument ’text’ will be the HTML template.
So switch back from ‘Expression’ to ‘Dynamic content’ and select the ‘File Content’ of the HTML template.
This will give you the following:
replace(outputs(‘HTML_Template’)?[‘body’])
Place a comma just before the closing ‘)’ like this
and add type: {ExampleColumnOne},
next select ExampleColumnOne from the row marked below
The final first compose step should look like this:
replace(outputs(‘HTML_Template’)?[‘body’], ‘{ExampleColumnOne}’, outputs(‘Get_item’)?[‘body/ExampleColumnOne’])
For the second compose step will will not use the template as the ’text’ but the output of the first replace. So the second compose step should look like this:
replace(outputs(‘Compose_-_Replace_ExampleColumnOne’), ‘{ExampleColumnTwo}’,outputs(‘Get_item’)?[‘body/ExampleColumnTwo’])
Lucky for us the remaining step is quite easy. It consists of the following:
In this demo, I have shown you how to implement a conversion of a SharePoint list-item to a PDF document using not a single line of code.
I can imagine that this can be used to generate PDF documents that are then sent by email. Although making this flow is doable, it does show its limitations. Because what if we now want to not only use two- but twenty columns? In that case we will also need 20 compose steps. You understand that in that case this solution is difficult to expand. This is often the problem with no-code solutions. In my next blog post I will show you how to overcome this problem by using Azure functions. Click here to read all about it.