Creating PDF Using Power Automate

Introduction

 
Creating PDFs from the data sources is a standard requirement in many cases. For instance, getting data from SPO list or getting from Power Apps, generating final invoice, and sending as an attachment, generating a certificate of completion on completion of training. in this article, we will see how we can generate a basic PDF using standard power automation actions. Kindly note that you do not need any premium actions in Power Automate. We will be using OneDrive for Business action in Power Automate.
 
Note
The HTML content cannot be greater than 2 MB for this PDF generation to work. This is the limitation of the Create File action for the ‘One drive for business’ connector. 
 

Steps

 
Step1
 
Login to your Power Automate portal (https://portal.office.com) using your O365 account then click on ‘Power Automate Tile’ on quick launch. Here I have logged into my developer tenant.
 
Creating PDF using Power Automate
 
Step 2
 
In the power automate page, make sure you are in the right environment and click on New - Instant cloud flow,
 
Creating PDF using Power Automate
 
Step 3
 
For this case, please select manually trigger a flow and click on create,
 
Creating PDF using Power Automate
 
Step 4
 
You will be navigated to the designer page, which looks like below,
 
Creating PDF using Power Automate
 
Step 5
 
Click on new step add ‘Compose’ action,
 
Creating PDF using Power Automate
 
Step 6
 
To make it simple, I am using following static HTML taken from W3schools.com and pasting it in compose action,
  1. <html>    
  2.    <head>    
  3.       <title>Page Title</title>    
  4.    </head>    
  5.    <body>    
  6.           
  7.       <h1>This is a Heading</h1>    
  8.       <p>This is a paragraph.</p>    
  9.     
  10.    </body>    
  11. </html>     
Creating PDF using Power Automate
 
Step 7
 
Now click on ‘New Step’ and add the ‘Create file’ action under the One Drive for the Business section,
 
Creating PDF using Power Automate
 
Step 8
 
You should see a screen similar to the one below. Now configure the ‘Create File’ as shown in the below screen capture.
 
Creating PDF using Power Automate
 
Now configure the ‘Create File’ as shown in the below screen capture.
 
Creating PDF using Power Automate
 
Folder Path
 
I am giving /PDF. Note that this path may or may not exist. If it doesn’t exist this action will create a folder called PDF.
 
File Name
 
For simplicity, I am giving it as ‘sample.html’. Note that the extension .html is important as we are parsing input data and converting it.
 
Creating PDF using Power Automate
 
Step 10
 
Next, add the ‘Convert File’ action under One drive for the business connector.
 
Creating PDF using Power Automate
 
Step 11
 
Configure the action as per the below screen capture.
 
Creating PDF using Power Automate
 
File - Id (the unique identifier of the file or folder)
 
Target Type - PDF
 
Step 12
 
Click on ‘New Step’ and search for ‘Send an Email (v2) action and add it. 
 
Creating PDF using Power Automate
 
Configure the action, as per the below screen capture.
 
Attachments Name -1 - Filename (under convert file dynamic values) 
 
Attachment Content - File content from the outputs of the ‘Convert file’ action.
 
Creating PDF using Power Automate
 
To: I am just hard coding my email
 
Subject - hard coding the value as ‘Sample PDF’
 
Body - hard coding the static information. Entered as ‘please find the attached PDF generated from Power Automate’.
 
Finally, name your flow and the same. In this case, I updated the title as ‘GeneratingSamplePDF’.
 
Creating PDF using Power Automate
 
The moment you update the ‘Title’ and ‘save’ it, you should see the following message in green. ‘The flow is ready to use. We recommend you to test it.
 
Creating PDF using Power Automate
 
Step 13
 
Now it's time to test the flow. Just click on the ‘Test’ at the top side of your design flow.
 
Creating PDF using Power Automate
 
Note
Flow and power automation are used interchangeably in this article. In my view, Power Automate is a technology that is used for business automation, and flow is your design that you implement to achieve it.
 
Step 14
 
In the launch window, select ‘Manually’ and ‘Test’.
 
Creating PDF using Power Automate
 
Before the flow begins to run, it might need permissions from the user. Since it is using One Drive For Business and email that is running under users context.  
 
Creating PDF using Power Automate
 
Finally, click on ‘Run Flow’ and you should be getting a message ‘Your flow run successfully started’.
 
Creating PDF using Power Automate 
 
Creating PDF using Power Automate
 
Below is the final design of the flow.
 
Creating PDF using Power Automate
 
Step 15
 
Go to your outlook inbox to check the PDF that was generated. Below is the email screen capture of the generated PDF.
 
Creating PDF using Power Automate
 

Conclusion

 
In this article, we have seen how we can use standard Power Automate action to generate PDF using sample data. In the next article, we will see how we can generate data from Power Apps, SharePoint list, and generate PDF on the fly. Again all using standard actions. Please stay tuned !!!
 
References
  • https://www.youtube.com/watch?v=Da4do2DxmJE&ab_channel=RezaDorrani
  • https://docs.microsoft.com/en-us/connectors/onedriveforbusiness/ 


Similar Articles