Work with the PDF function (experimental)
The PDF function allows you to generate a PDF document from the contents of a screen or certain types of controls. You can take the generated PDF and pass it to action connectors such as the Office 365 Outlook connector, or pass it to a Power Automate flow to achieve automation scenarios.
Important
- 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.
- The behavior that's described in this article is only available when the PDF function (experimental) feature is turned on in Settings > Upcoming features > Experimental.
- Send your feedback in the Power Apps experimental features community forum.
In this article, we'll learn how to use the PDF function to create a PDF and use the generated PDF in several different ways.
Prerequisites
- Sign up for Power Apps.
- sign in and create a canvas app. More information: Create a blank canvas app from scratch
Enable the PDF feature
Since the PDF function is an experimental feature, it's disabled by default. To use the PDF feature, you'll need to turn it on manually.
To enable the PDF function, open a new or edit an existing app in Power Apps Studio.
On the command bar, select Settings.
Select Upcoming features.
On the Experimental tab, set the toggle to On for PDF function.
Use the PDF function to generate a PDF
You can use the PDF function in any behavior property to generate a PDF. In the example below, we'll use the PDF function in the OnSelect
property of a button. You can also use OnVisible
, OnHidden
, or any other behavior property.
Select an existing button or add a new button to your canvas app.
In the
OnSelect
property of the button, enter the PDF function and enter the target of the PDF function as a parameter.
In this example, we'll target the screen. In our example, the name of the Screen isSubmitInspectionScreen
. The name of your screen may be different. Enter the formula:PDF(SubmitInspectionScreen);
In the upper-right corner, select Save and publish.
Play the app.
Select the button you added. When you select the button, the PDF is generated and stored in memory for future use.
The PDF function can only target content on the screen that is currently visible. You can pass in the entire screen as we're doing in this example, or you can limit what content that you want to pass by specifying a container or gallery. More information: PDF function in Power Apps (experimental).
Note
- These examples work best when using an app with multiple controls.
SubmitInspectionScreen
is the name of the screen in this example. If the name of the screen where you've placed your button is notSubmitInspectionScreen
, enter the name of the screen where you've added the button.- To see the generated PDF, see the next steps below.
Work with the generated PDF
There's many different methods to work with a generated PDF such as using the PDF Viewer control, use an action connector, and use in a Power Automate flow.
Method 1: Using the PDF Viewer control
In this example, we'll view the generated PDF using the PDF Viewer control.
In the canvas app that you created, select the button that you created in the previous steps or add a new button.
In the button's
OnSelect
property, enter the following formula:Set(myPDF, PDF(SubmitInspectionScreen));
On the command bar, select Insert > PDF viewer (experimental).
From the properties list, select the Document property and then enter myPDF in the formula bar.
In the upper-right corner, select Save and publish.
Play the app.
Select the button you added. When you select the button, the PDF is generated and stored in the variable, and is visible in the PDF viewer control.
Note
The PDF viewer control will appear as a black shape inside the generated PDF. To exclude the PDF Viewer control from the generated PDF, place the desired PDF content inside of a container or gallery and target that instead of the screen. For example,
PDF(Container1)
orPDF(Gallery1).
Method 2: Use an action connector
In this example, we'll generate a PDF that we then attach and send as an email. In this example, we'll use the Office 365 Outlook connector to send the email. More information: 365 Outlook connector
In the canvas app that you created, select the button that you created in the previous steps or add a new button.
In the button's
OnSelect
property, enter the following formula:Office365Outlook.SendEmailV2( "sample@email.com", "New Safety Inspection" "A new safety inspection has been submitted for your review. Please see attached.", { Attachments: Table( { Name: "submittedInspection.pdf", ContentBytes: PDF(SubmitInspectionScreen) } ) } );
Note
A sample email address has been included in this formula example.
In the upper-right corner, select Save and publish.
Play the app.
Select the button that you added. When you select the button, the PDF is generated, and an email is sent to the specified email address with the generated PDF included as an attachment.
Method 3: Use in a Power Automate flow
In this example, we'll generate a PDF that then gets passed to a Power Automate flow for storage. In this example, we use the SharePoint connector to store the PDF in a document library. More information: SharePoint connector.
In the canvas app that you created, select the button that you created in the previous steps or add a new button.
From the app authoring menu, select Power Automate > Create new flow.
Select Create from blank.
For this example, we'll use the Power Apps V2 trigger. To add it, select Menu for Power Apps (...) and then select, Delete.
In the search box, enter PowerApps(V2) and then select the trigger to add it.
Select the PowerApps V2 trigger to expand the flow node and then select, Add an input.
Select File for type of user input.
Select Add an input and choose the Text for type of user input. Rename the input to File Name and update the description to Please enter the name of the file.
Select +New step to add an action. In the search box, enter SharePoint. In the list of available SharePoint actions, select Create file.
Choose a site from the Site Address drop down or select Enter custom value to enter a URL for a SharePoint site that have permission to add files to.
For Folder Path select the Show Picker folder icon and then select a document library from the list. You need to you have permissions to add files to this folder.
Select the File Name input. From the Dynamic Content tab, select a file name under PowerApps (V2).
Select the File Content input and then select, File Content from the list.
Select Save.
Select the Close to close the dialog box.
The Power Automate pane refreshes, and you'll see the flow that you created.
Select the button on the canvas. In the button's
OnSelect
property, enter the formula:'PowerAppV2->Createfile'.Run( "NewInspectionReport.pdf", { file: { name: "NewInspectionReport.pdf", contentBytes: PDF(InspectionDetails) } } );
In the upper-right corner, select Save and publish.
Play the app.
Select the button you added. When you select the button, the Power Automate flow runs and adds the generated PDF into the document library.
See also
Feedback
Submit and view feedback for