Your Microsoft Technology Development and Consulting Experts - Operating since 2000
Exporting data to PDF from Power Apps is a common requirement in business applications. While Power Apps doesn't have a built-in "Export to PDF" function, we can achieve this functionality by combining Power Apps with Power Automate (Flow) to create professional-looking PDF exports of your app data.
In this guide, I'll show you a streamlined approach to PDF exports, including how to:
Head over to my YouTube channel Chino Does Stuff to watch the video tutorial, there you will see a variety of videos with loads of tricks and tips on the entire Power Platform suite.
For this tutorial, we'll use a simple "Issues Tracker" Power App that logs issues to a SharePoint list. When a new issue is created, our Flow will automatically generate a PDF export of that issue and attach it to the SharePoint item.
The SharePoint list contains basic fields for our issue tracking:
Let's start by creating a Flow that will handle the PDF export process. This Flow will trigger whenever a new item is created in our SharePoint list.
Start by creating a new cloud flow in Power Automate with a SharePoint trigger:
If you want to include images in your PDF (like a company logo), you'll need to retrieve that image file first:
This step retrieves the binary content of your image file, which we'll encode into the HTML later.
Now, we need to create the HTML structure that will become our PDF:
For a basic structure with just text, you could use:
The tricky part is adding an image. To include an image in your PDF, you'll need to encode it as a base64 string directly in your HTML:
Combining these, your complete HTML might look like:
Before converting to PDF, we need to save our HTML as a file:
concat(triggerOutputs()?['body/Title'], '.html')
This creates a temporary HTML file in OneDrive, which we'll then convert to PDF.
Now comes the magic step - converting our HTML to PDF:
This step handles the conversion from HTML to PDF, giving us a properly formatted document.
Now that we have our PDF, let's save it to SharePoint where our Power App can access it:
Finally, we need to associate this PDF with our original SharePoint item:
This creates a relationship between your PDF and the SharePoint item, making it appear as an attachment.
Here's a summary of the complete flow:
Once your flow is set up, it's time to test the solution:
Opening the PDF should show your formatted content, including any images you've included.
You can enhance your PDF output in several ways:
Remember that you're essentially creating a web page that will be converted to PDF, so most HTML and CSS techniques will work.
The most challenging part of this solution is including images in your PDF. The key is to:
This approach works for most image types (PNG, JPEG, etc.) but be mindful of file sizes, as large images will increase processing time.
For best results with the PDF conversion:
Exporting to PDF from Power Apps is straightforward once you understand the process. By leveraging Power Automate, we can create professional-looking PDF exports that include both text and images, providing a complete solution for document generation.
This approach offers several advantages:
With these tools, you can enhance your Power Apps solutions with professional document generation capabilities, meeting the needs of business users who require formatted outputs from their applications.
If you'd like to see more Power Platform development tutorials, please head over to the YouTube channel and leave a comment there. I actively monitor and respond to all YouTube comments!
Marcello is a lead developer at Powerplatform Experts, an expert in, Computer Science, Power Platform integration and founder of the YouTube channel ChinoDoesStuff. If you have any questions, please feel free to get in contact at via the form below.
Copyright © 2024. Brayalei Pty Ltd T/As Office Experts Group. ABN 32 093 067 737. ACN 093 067 737. All Rights Reserved.