An often requested feature and requirement we hear from the field, is the ability to create a PDF directly from within PowerApps - finally, you can achieve this using this newly released PDF function in Power Apps!
Firstly, it is important to note that this is an experimental feature. Experimental features aren't meant for production use and may have restricted functionality. These features are available before an official release so that customers can get early access and provide feedback. More information: Understand experimental, preview, and retired features in canvas apps
Here at Dapt, we put this new functionality to the test and have started implementing this into a number of our test applications. Our clients are already talking about how they can enhance their production apps when it lands in general availability!
In this blog post we are going to talk about how to enable this feature, the various configuration options and what they mean, and finally walk you through the simple steps and explain the formula for sending a PDF directly to the currently logged-in user with a single click – all this without using any Power Automate!
Enabling the PDF Function
To turn on this feature you will first need to browse the settings within PowerApps and locate the PDF function feature within the Experimental tab and select enable.
The PDF function Options
Once enabled you will be able to start adding the PDF function to your formulas by simply typing PDF in the formula bar. By setting a variable to the output of this function, it will allow you to store this data as a blob and use it in various ways such as the data source for a PDF viewer or as an attachment to an email which we will demonstrate below.
When using the PDF function there are a number of additional attributes both required and optionally available to further configure the PDF settings.
Screen or control name (Required)
The screen or control containing the content to use to generate the PDF. Supported controls: Vertical Gallery, Vertical Layout Container, Horizontal Layout Container, Container, Screen.
Size (Optional)
Controls the dimensions of the generated PDF. The default value depends on the app user's locale; Letter for US and Canada and A4 for other locales.
DPI (Optional)
Controls the scaling/resolution of the generated PDF. Must be a value greater than 0. Content exceeding the space allowed by the specified margins may result in a higher effective DPI. The default value is 96.
Margin (Optional)
A string specifying the size of the space reserved between the content and the outer edge of the generated PDF. Each margin of the generated PDF (top, right, bottom, left) can support a different value. Supported units of measurement for this value include; in, cm, mm, pt, and px. The default value is 0.5 inches (12.7 mm) for all margins.
Orientation (Optional)
Controls whether the generated PDF has a portrait (vertical) or landscape (horizontal) orientation. The default value is portrait (vertical).
Expand Containers (Optional)
Boolean. Controls whether certain containers with contents that exceed their allocated size expand to display all content in the generated PDF. Impacted controls include screens, containers, vertical and horizontal containers, vertical fixed-height galleries (not nested), forms, and scrollable canvas controls. The default value is false.
Creating a PDF and sending it via Email
In a scenario where there is a requirement to generate a PDF from an on-screen gallery and instantly email the result to the currently logged-in user you may configure the formula somewhat as follows:
In the ‘On Select’ property of a button add the following formula:
Set(PDFBlob, PDF(GalleryName,{ExpandContainers: true, Orientation:Landscape,Size:A4}));
This will set a variable named ‘PDFBlob’ to the output of the gallery named GalleryName in this example (simply replace as required).
Within your App, click on the Data icon and add a new connector and select the Office365 Outlook Connector as this is what we will use to send the email:
Once connected, you can then use the previously set variable and use its contents to add to an attachment file and send it to the logged-in user by adding the following formula after the previous:
Office365Outlook.SendEmailV2(User().Email,"Email Subject","Email Body",{Attachments:Table({Name:"PDF Name.pdf",ContentBytes:PDFBlob})})
This will very simply and instantly send the email to the currently logged-in user with the details used within the various email attributes and can obviously be further customized to any required specification.
The formatted formula in full:
Set(
PDFBlob,
PDF(
TestGallery,
{
ExpandContainers: true,
Orientation: Landscape,
Size: A4
}
)
);
Office365Outlook.SendEmailV2(
User().Email,
"Email Subject",
"Email Body",
{
Attachments:Table(
{
Name:"PDF Name.pdf",
ContentBytes:PDFBlob
}
)
}
)
Known limitations
There are a few known limitations to the function currently as to be expected, but as this is still an experimental feature we expect there will be further enhancements in future releases.
Certain controls aren't currently supported. These include charts, Power BI tile, Map, and some configurations of third-party PCF controls.
Nested Galleries aren't supported.
Non-Latin script types and font weights and styles such as bold and italic may not appear in the generated PDF for some fonts.
The creation of fillable PDFs isn't supported.
Important Info
Test and use the PDF function in your Apps right now but be mindful that it is still an experimental feature and of the following:
PDF generation happens on the device where the app is running. Different devices such as desktop computers and mobile devices will have different capacities when you're generating a PDF.
Generating a PDF with an exceptionally large file size can result in the app crashing. This depends on the capacity of the device that you're running the app on. Be aware of the size and number of images and how much data you want to include in the generated PDF, specifically for apps intended for use on a mobile device.