Insights Using Power Automate to create PDF files from SP List Items (without 3rd party products or premium licensing)

Using Power Automate to create PDF files from SP List Items (without 3rd party products or premium licensing)

Using Power Automate to create PDF files from SP List Items (without 3rd party products or premium licensing) 

There are a variety of reasons you may need to create a pdf out of a SharePoint list item, perhaps the information needs to be printed or the list is used to produce an invoice for a customer. Whatever the reason, Power Automate can be used to facilitate the process. There are 3rd party and custom solutions for creating pdfs from various sources and if you have a high volume that you need to process one of those would likely be a better solution, but if you needs are simpler and your budget low then you could use the out of box Power Automate actions. 

The core of the process revolves around creating an html file and using the OneDrive for Business Convert File action to create a pdf out of the html file. Once you have the output of the Convert File action, you can do anything you would normally do with a file (I.e., save it somewhere, send it as an email attachment, etc.) 

Dependencies 

  • OneDrive for Business 
  • Some knowledge of HTML 

The Process 

The overall process needed to create a pdf document out of a SharePoint list item involves the following steps: 

  • Taking the list item’s fields to create some html 
  • Creating a temporary html file in OneDrive 
  • Converting the temporary html file’s contents to a pdf 
  • Saving the converted pdf to its desired location 

Creating the File 

The first step in the process is to take the SharePoint list item and put it in a format that we can use to create a file. Here we created a variable that we will be filling with html and references to our list item’s fields. You are able to get a bit more creative with your html with tables, styling, and other more advanced html tags. 

We can take that html filled variable and create a html file in OneDrive. We create the file in OneDrive because it will need to be there to use OneDrive’s Convert File action to generate the pdf content. 

Converting the file 

After the html file is created, we can then use OneDrive’s Convert file action to convert the original html file to a pdf. There are also a couple other file type options.  

The Convert file action does not replace the original file nor create a new file within OneDrive so we must follow the Convert file action with a Create file. In this case I wanted the file in SharePoint, so I used a SharePoint Create file action. The file contents of the new file should be the Body output from the Convert file action. This will create a new pdf file in SharePoint with the pdf contents generated out of the Convert file. 

Clean up 

Running this process will leave behind the html file we created in OneDrive. To keep the environment clean and prevent the buildup of unwanted files, we need to delete the html file when we are done. To do this, we put a OneDrive Delete file action at the end of our flow and pass it the Id of the html file we created. 

Notes 

As noted above, this process is intended for low volume, non-critical processing. The html formatting can be a bit frustrating as well to get your data formatted in just the right manner to fit correctly on the generated page.  

One other important note is that the generated pdf can only be in portrait and there is currently no way of generating a pdf in landscape through this method.