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.
Step 2
In the power automate page, make sure you are in the right environment and click on New - Instant cloud flow,
Step 3
For this case, please select manually trigger a flow and click on create,
Step 4
You will be navigated to the designer page, which looks like below,
Step 5
Click on new step add ‘Compose’ action,
Step 6
To make it simple, I am using following static HTML taken from W3schools.com and pasting it in compose action,
- <html>
- <head>
- <title>Page Title</title>
- </head>
- <body>
-
- <h1>This is a Heading</h1>
- <p>This is a paragraph.</p>
-
- </body>
- </html>
Step 7
Now click on ‘New Step’ and add the ‘Create file’ action under the One Drive for the Business section,
Step 8
You should see a screen similar to the one below. Now configure the ‘Create File’ as shown in the below screen capture.
Now configure the ‘Create File’ as shown in the below screen capture.
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.
Step 10
Next, add the ‘Convert File’ action under One drive for the business connector.
Step 11
Configure the action as per the below screen capture.
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.
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.
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’.
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.
Step 13
Now it's time to test the flow. Just click on the ‘Test’ at the top side of your design flow.
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’.
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.
Finally, click on ‘Run Flow’ and you should be getting a message ‘Your flow run successfully started’.
Below is the final design of the flow.
Step 15
Go to your outlook inbox to check the PDF that was generated. Below is the email screen capture of the generated PDF.
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/