Your Microsoft Technology Development and Consulting Experts - Operating since 2000

Location
Australia WideSydney, NSWMelbourne, VicBrisbane, QldPerth, WAAdelaide, SACanberra, ACTNorthern Rivers, NSWWollongong, NSWRichmond, VicDarwin, NT
emailconsult@officeexperts.com.au
email1300 102 810
Office experts logo
Microsoft certified logo
Contact Us

Author: Marcello Brocchi

Reading time: 6min

Export to PDF in Power Apps - The Best Way to Do It!

Introduction

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:

Prefer to Watch the Video?

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.

The Sample Scenario

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:

Building the Power Automate Flow

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.

Step 1: Create a New Cloud Flow

Start by creating a new cloud flow in Power Automate with a SharePoint trigger:

  1. Navigate to Power Automate and select "Create" > "Cloud flow"
  2. Choose the "When an item is created" trigger for SharePoint
  3. Select your SharePoint site and the "Issues" list

Step 2: Get an Image for Your PDF (Optional)

If you want to include images in your PDF (like a company logo), you'll need to retrieve that image file first:

  1. Add a "Get file content" action from SharePoint
  2. Select your SharePoint site and document library
  3. Enter the file path to your image (e.g., "logo_small.png")

This step retrieves the binary content of your image file, which we'll encode into the HTML later.

Step 3: Compose Your HTML Content

Now, we need to create the HTML structure that will become our PDF:

  1. Add a "Compose" action to your flow
  2. In the "Inputs" field, create the HTML structure using values from your SharePoint item

For a basic structure with just text, you could use:

Loading code...

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:

Loading code...

Combining these, your complete HTML might look like:

Loading code...

Step 4: Create a Temporary HTML File

Before converting to PDF, we need to save our HTML as a file:

  1. Add a "Create file" action for OneDrive
  2. Select the root folder of your OneDrive (or any folder you prefer)
  3. For the file name, use a dynamic expression: concat(triggerOutputs()?['body/Title'], '.html')
  4. For the file content, use the output from your Compose step

This creates a temporary HTML file in OneDrive, which we'll then convert to PDF.

Step 5: Convert the HTML File to PDF

Now comes the magic step - converting our HTML to PDF:

  1. Add a "Convert file" action from OneDrive
  2. For the "File", select the ID from the previous "Create file" step
  3. Set the target format to "PDF"

This step handles the conversion from HTML to PDF, giving us a properly formatted document.

Step 6: Save the PDF to SharePoint

Now that we have our PDF, let's save it to SharePoint where our Power App can access it:

  1. Add a "Create file" action for SharePoint
  2. Select your SharePoint site and a document library (e.g., "Issues Attachments")
  3. For the file name, use the file name from the Convert step
  4. For the file content, use the file content from the Convert step

Step 7: Link the PDF to Your SharePoint Item

Finally, we need to associate this PDF with our original SharePoint item:

  1. Add an "Update file properties" action for SharePoint
  2. Select your SharePoint site and document library
  3. For the ID, use the ID from the previous "Create file" step
  4. Add a property: "ParentID" = ID from the trigger (SharePoint list item ID)

This creates a relationship between your PDF and the SharePoint item, making it appear as an attachment.

Complete Flow Structure

Here's a summary of the complete flow:

Loading code...

Testing the Solution

Once your flow is set up, it's time to test the solution:

  1. Open your Power App and create a new issue
  2. Enter a title and description, then save the record
  3. The flow should trigger automatically
  4. After the flow completes, you should see a PDF attachment on your SharePoint item

Opening the PDF should show your formatted content, including any images you've included.

Customising Your PDF Output

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.

Key Challenges and Solutions

Including Images

The most challenging part of this solution is including images in your PDF. The key is to:

  1. Retrieve the image file using "Get file content"
  2. Encode the image as a base64 string within an HTML image tag
  3. Include the content type to ensure proper rendering

This approach works for most image types (PNG, JPEG, etc.) but be mindful of file sizes, as large images will increase processing time.

HTML Formatting

For best results with the PDF conversion:

Conclusion

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!

About the Author

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.

Marcello Brocchi

Contact Us

Get in touch with our team for general inquiries and support. We're here to help with any questions you might have about our services.

Request a Quote

Need pricing for a specific project? Fill out our quote form and we'll provide you with a detailed estimate tailored to your needs.