Export a Power Apps gallery as PDF file using the new PDF function, and email it with the Outlook connector

With the recently experimental PDF feature that is available from Power Apps authoring versions 3.22094.* we are now able to export screens, galleries and containers to PDF and obtain the output of this export as bytes, and use it on the PDF viewer or send it to a flow, so we can save it to SharePoint, OneDrive and etc.

The advantage of this approach instead using the Print function to print screens is that we can get the full content of galleries/containers in a PDF, so we are not limited to only what is displayed in the screen.

The text in the PDF file exported using this function is also selectable, so we are here exporting ‘real’ PDFs, and not screenshots from screens into PDF files:

Sending the exported PDF in an email message

Consider you have a gallery with content you want to export as below. The gallery content is not fully visible as below:

The PDF export function is really simple, you can use it to generate content directly or to save it in variables to be used later.

But in this example let’s only call it directly from the Office 365 Outlook Connector (Send an email V2) action.

Add the Office 365 Outlook connector to your app, and then simply add the code as the example below to a button/icon to Export the gallery to PDF and send the content as an Attachment:

    "Your pdf",
    "Your PDF is attached",
        From: User().Email,
        Attachments: Table(
                ContentBytes: PDF(
                        Orientation: PaperOrientation.Portrait,//Portrait or Landscape
                        Size: PaperSize.A4,//Select your page size
                        DPI: 150,
                        ExpandContainers: true /* This property makes sure the full content of gallery/containers is expanded as PDF */
                Name: "Export.pdf"

Note that the Attachments parameter in the SendEmailV2 action expects a table of attachment objects with the ContentBytes and FileName as parameters. As ContentBytes we are using the PDF function to export it directly and send in the Email.

For the PDF function, use the proper DPI and page sizes you wish, but keep the ExpandContainers property value as true if you want to export the full gallery.


After the button is clicked, the recipient will receive an email with a PDF copy of the gallery attached, as below:

Note: As of now, the PDF export function will only export items that were already loaded in the app. So for example if you have a SharePoint list with 8000 items, by default the gallery component loads the items in batches as you scroll (not all the 8000 at first), and if you call the PDF function in a situation like this, it will export only the items that were already loaded into the gallery.


[New] Create PDF from Power Apps with PDF function by Hiro Nagao

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *