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: 4min

Power Apps PDF Function - The Best Way to Export to PDF?

Introduction

Microsoft has added a new PDF generation capability to Power Apps, making it easier than ever to create PDF documents directly from your applications. While this feature is still labeled as experimental, it's available now and provides a significant improvement over previous workarounds.

In this guide, I'll show you how to enable and use the PDF function, create PDFs from your screens or containers, and provide users with a seamless experience to view and download their generated documents.

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.

Enabling the Experimental PDF Function

Since the PDF function is still in experimental status, you'll need to explicitly enable it in your app:

  1. Open your Power App in the maker portal
  2. Click the Settings gear icon in the top right
  3. Select "Upcoming features"
  4. Go to the "Experimental" tab
  5. Find the PDF option and toggle it to "On"
  6. Save your changes

Once enabled, you'll have access to the PDF function and the PDF Viewer control in your app.

How the PDF Function Works

The PDF function in Power Apps is quite straightforward but powerful. It converts a screen or container into a PDF document and returns that document as a blob (binary large object) that you can then work with programmatically.

The basic syntax is:

PDF(ScreenOrContainer [, PDFOptions])

Where:

The function returns a blob that you can use to:

Creating a PDF Export Button

Let's implement a solution that creates a PDF and allows users to view and download it. We'll use a flow to save the PDF to SharePoint and then open it in a new browser tab.

First, add a button to your app with an icon that suggests PDF functionality. Then use this code for the OnSelect property:

Loading code...

This code does three things:

  1. Creates a PDF from the current screen and stores it in a variable
  2. Uses a flow to save the PDF to SharePoint (more on this below)
  3. Opens the saved PDF in a new browser tab using the Launch function

Connecting to SharePoint for PDF Storage

The code above references a flow called "SaveFileToSharePoint". This is a standard Power Automate flow that saves a file to a SharePoint document library. If you don't already have this flow, you'll need to create it.

Note: For detailed instructions on creating a file upload flow, check out my video on "File Attachments in Power Apps" which explains how to set up this flow step by step.

The flow should:

Customising Your PDFs

The PDF function also accepts an options record that allows you to customise various aspects of the generated PDF:

Loading code...

You can customise:

You can also choose to convert only a specific container instead of an entire screen, which gives you more control over what appears in the PDF.

Using the PDF Viewer Control

If you want to show a preview of the PDF before saving or downloading, you can use the experimental PDF Viewer control:

Loading code...

Simply add the PDF Viewer control to your screen and set its Document property to the blob variable created by the PDF function.

Limitation: As of this writing, the PDF Viewer control is very basic and doesn't include controls for zooming, downloading, or printing. For a better user experience, I recommend using the approach described earlier to open the PDF in a new browser tab.

Tips for Better PDF Generation

To get the best results from the PDF function:

Use Cases for PDF Generation

The PDF function opens up many possibilities for Power Apps:

Conclusion

The new PDF function in Power Apps is a welcome addition that makes it much easier to generate PDF documents directly from your apps. While still experimental, it works well and provides a cleaner, more integrated solution than previous workarounds.

By combining the PDF function with a SharePoint storage flow and the Launch function, you can provide users with a seamless experience for creating, viewing, and downloading PDFs from your Power Apps.

As the feature evolves out of experimental status, we can expect more capabilities and better integration with the rest of the Power Platform. In the meantime, this approach offers a practical solution for PDF generation needs.

If you'd like to see more Power Apps tips and techniques, 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.