From Screen to PDF: Generate, Preview, and Download Documents with Power Apps
Learn how to use the PDF function to capture any control or screen as a PDF, view it, and save a copy locally—all with a standard Power Apps license.
Generating a PDF directly from a canvas app used to mean third‑party services or complex workarounds. With the native PDF function, you can capture any control or screen as a PDF file without leaving Power Apps—and it works with a standard license. In this guide you’ll build an invoice viewer that creates a PDF, lets you preview it, and then downloads a copy to your device.
Let’s walk through the entire flow: setting up a SharePoint list, building the app UI, generating the PDF, viewing it in a dedicated screen, and finally saving it using Power Automate.
Scenario Overview
Consider a small consulting firm that needs to turn service invoices into PDFs. Their app displays invoice details in a read‑only form, and the user should be able to:
- Generate a PDF of the current invoice
- Preview the PDF inside the app
- Download the PDF to their device
We’ll create a canvas app that does exactly that. The data lives in a SharePoint list named Invoices.
Setting Up the Data Source
Create a new SharePoint list with these columns:
| Column Name | Type |
|---|---|
InvoiceNumber | Number |
ClientName | Single line of text |
IssueDate | Date only |
ServiceDesc | Multiple lines of text (plain) |
TotalAmount | Currency (US Dollar) |
CompanyLogo | Image (full size) |
Add one sample row that we’ll display in the app:
- InvoiceNumber:
1001 - ClientName:
Contoso Consulting - IssueDate:
5/12/2026 - ServiceDesc:
Q2 strategic planning sessions and market analysis - TotalAmount:
4500.00 - CompanyLogo: Upload a company logo image
Now create a new blank canvas app in tablet layout, and connect it to this list via the Data pane.
Building the Invoice Form
We cannot generate a PDF directly from an Edit Form, so we place the form inside a container and generate the PDF from that container.
Step 1: Insert a Vertical Container
Add a Vertical container to the screen, then set its key properties in the formula bar:
con_InvoiceContainer.X = 0 con_InvoiceContainer.Y = 0 con_InvoiceContainer.Width = App.Width con_InvoiceContainer.Height = App.Height con_InvoiceContainer.LayoutAlignItems = LayoutAlignItems.Stretch
Step 2: Add a Title Label
Inside the container, place a label for the header. Set its Text to "Invoice Summary", its Fill to a dark blue, and the font color to white.
Step 3: Insert an Edit Form
Inside the same container, add an Edit form control (from the Insert menu). Set its DataSource to the Invoices list. In the properties pane, choose a vertical layout with 1 column, and add the fields you want: ClientName, IssueDate, ServiceDesc, TotalAmount, and CompanyLogo.
Use this expression in the Item property of the form to load the first record:
LookUp('Invoices', InvoiceNumber=1001)Switch the form to read‑only mode so users cannot accidentally edit the data. Set its DisplayMode to DisplayMode.View.
At this point your screen should resemble a typical invoice viewer.
Generating the PDF
The PDF function works with any control or screen. We’ll capture the container con_InvoiceContainer.
First, ensure the PDF feature is enabled: go to Settings (File menu) > Upcoming features > PDF function and toggle it on if it’s not already.
Next, add a PDF icon (from the Icons menu) to the title bar. In its OnSelect property, write:
Set(
varInvoicePDF,
PDF(
con_InvoiceContainer,
{ExpandContainers: true}
)
);
Navigate('InvoicePreviewScreen')The ExpandContainers argument tells the PDF function to fully render any containers that might contain hidden or off‑screen controls. This prevents a blank or truncated PDF.
Previewing the PDF
Create a new screen named InvoicePreviewScreen. Add a dark‑blue title bar with the text “Invoice PDF” and a left‑arrow icon in the top‑left corner.
In the OnSelect of the arrow, clear the variable and go back:
Set(varInvoicePDF, Blank());
Navigate('Invoice Screen')Now insert a PDF viewer control (under Media) and size it to fill the rest of the screen. Set its Document property to varInvoicePDF.
Run the app. Tap the PDF icon, and you should see the PDF appear in the viewer.
Saving a Copy to the Device
To let users download the PDF, we need a temporary storage location and a small Power Automate flow that returns a download link.
Step 1: SharePoint Document Library
Create a new document library named Exported Invoices. No extra columns are needed.
Step 2: Power Automate Flow
Open Power Automate and create an instant flow that triggers from Power Apps. Call it SaveInvoicePDF.
- Trigger: Use the PowerApps button trigger.
- Add an input called
fileof type object (make it required). This object will havename(string) andcontentBytes(binary data). - Action: Create file (SharePoint). Choose your site and the Exported Invoices library. Set the File Name to:
triggerBody()['file']['name']
Set the File Content to:
triggerBody()['file']['contentBytes']
- Action: Respond to PowerApps (or “Return to Power Apps”). Add an output named
pathof type string, and set its value to a download URL that bypasses the SharePoint document viewer. Use this pattern (replace<tenant>,<site>, and<library>with your actual values):
https://<tenant>.sharepoint.com/sites/<site>/_layouts/15/download.aspx?SourceUrl=/sites/<site>/<library>/@{outputs('Compose_FileName')}(You can build the file name inside the flow with a Compose action that concatenates the file name from the trigger.)
Test the flow and ensure it returns the correct path.
Step 3: Wire Up the Download in the App
Back in Power Apps, add the SaveInvoicePDF flow to the app via the Data pane.
On the InvoicePreviewScreen, insert a save icon (or button) and set its OnSelect to:
Download(
SaveInvoicePDF.Run(
{
name: "Invoice_" & Text(Now(), "yyyymmddhhmmss") & ".pdf",
contentBytes: varInvoicePDF
}
).path
)The Download function takes a URL and forces the browser to download the file. The flow returns the path of the file we created in SharePoint, now prefixed with the download.aspx URL.
Run the app again, preview the PDF, and tap the save icon. Your device should download the PDF.
Performance and Security Considerations
- The PDF function renders the control client‑side. Very large containers with many controls (especially images) can impact memory and speed. Use
ExpandContainers: trueto catch any content that might be collapsed. - Because PDF rendering is local, no data leaves your app session—the generated PDF exists only in the app until you export it via the flow.
- For the flow, ensure the service account or the user running the flow has write permissions to the document library.
- If you plan to share the PDF link externally, consider using a SharePoint permission‑controlled library.
Common Mistakes and Troubleshooting
| Problem | Likely cause | Fix |
|---|---|---|
| PDF is blank | Container does not include all controls, or ExpandContainers is missing. | Verify the container wraps every control. Add {ExpandContainers: true}. |
| PDF viewer shows nothing | Variable varInvoicePDF is blank or not in scope. | Make sure the variable is set before navigating to the preview screen. |
| Form appears editable | DisplayMode of the form is not View. | Set DisplayMode = DisplayMode.View. |
| Download fails or no file saved | Flow input is incorrect or permissions are missing. | Check flow run history. Ensure the SharePoint library exists and the user has write access. |
| Download URL not working | The download.aspx URL is malformed. | Test the URL manually in a browser to see if it triggers a download. |
Final Recommendation
The native PDF function is a game‑changer for simple document generation inside Power Apps. It is fast, license‑friendly, and fully integrated. Combine it with a flow for persistent storage, and you have a self‑contained solution for generating and delivering PDFs from your app.
For advanced scenarios (e.g., multi‑page PDFs or complex layouts), look into using HTML templates with the JSON function, but for most single‑page forms the PDF function is your best bet.
References
- Original source: Matthew Devaney – Power Apps PDF Function: Create, View & Download PDFs
- Microsoft Learn: PDF function in Power Apps (check the latest official documentation)
- Microsoft Learn: Download function
Learn how small coding practices—like using descriptive names, flattening conditions, and simplifying logic—can make your apps easier to update and less error-prone.
Move past the gallery and discover the hidden patterns for validation, navigation, and smart submission handling in your data entry forms.
PowerShell unlocks admin capabilities that the Power Platform admin center simply doesn’t offer—from recovering deleted apps to blocking trial licenses. Here’s how to wield them safely.