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

michelcarloMicrosoft 3652 years ago9 Views

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:

Office365Outlook.SendEmailV2(
    "user@tenant.onmicrosoft.com",
    "Your pdf",
    "Your PDF is attached",
    {
        From: User().Email,
        Attachments: Table(
            {
                ContentBytes: PDF(
                    galSessionsData,
                    {
                        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.

Results

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.

Reference

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

The post Export a Power Apps gallery as PDF file using the new PDF function, and email it with the Outlook connector appeared first on michelcarlo.

Original Post https://michelcarlo.com/2022/10/02/export-a-gallery-as-pdf-and-send-it-as-email-attachment-from-power-apps-using-the-office-365-outlook-connector/

Leave a reply

Join Us
  • X Network2.1K
  • LinkedIn3.8k
  • Bluesky0.5K
Support The Site
Events
March 2025
MTWTFSS
      1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31       
« Feb   Apr »
Follow
Sign In/Sign Up Sidebar Search
Popular Now
Loading

Signing-in 3 seconds...

Signing-up 3 seconds...