Post

Power Apps PDF Viewer for a SharePoint Document Library, without a Flow, from Reza Dorrani

How to display a PDF from a SharePoint document library directly in a Power Apps PDF Viewer control, using SharePoint's download.aspx URL pattern instead of a Power Automate flow.

Power Apps PDF Viewer for a SharePoint Document Library, without a Flow, from Reza Dorrani

TL;DR: A SharePoint “link to this file” opens the preview page, not the PDF. Point the PDF viewer’s Document property at SharePoint’s download.aspx endpoint instead: "https://contoso.sharepoint.com/sites/Projects/_layouts/15/download.aspx?SourceUrl=" & EncodeUrl("/sites/Projects/" & Gallery1.Selected.'Full Path'). No flow needed. The PDF viewer is still an experimental control, so keep ShowControls on as the fallback to open the file in the browser.

Point a Power Apps PDF viewer control’s Document property at a normal SharePoint document link and you get a blank control or a broken preview. Reza Dorrani shows why, and the one-line fix.

💡 Challenge

You have a gallery on a SharePoint document library and want to show the selected PDF inside the app. The obvious value, the item’s link, does not work: it opens SharePoint’s own web viewer, an HTML page with a viewer built in. The PDF viewer control expects the opposite: its Document property must link directly to the PDF file, and HTML views of the document or server redirects are not supported.

✅ Solution

SharePoint has a _layouts/15/download.aspx endpoint. It takes the server-relative path of a file in the SourceUrl parameter and returns the file itself instead of the preview page. Build that URL with a text formula from the gallery item and set it as the PDF viewer’s Document. That replaces the flow that fetches the file and hands it back to the app.

🔧 How It’s Done

1. Add the library and a gallery.

🔸 Add the SharePoint document library as a data source and set a gallery’s Items to it, for example Documents.

🔸 Every file in the library has the column Full Path, the path of the file relative to the site, for example Shared Documents/Reports/Q1 report.pdf.

2. Build the download URL.

🔸 Add a PDF viewer control and set its Document property:

"https://contoso.sharepoint.com/sites/Projects/_layouts/15/download.aspx?SourceUrl=" &
EncodeUrl("/sites/Projects/" & Gallery1.Selected.'Full Path')

🔸 Replace contoso and /sites/Projects/ with your tenant and site. The site part appears twice: once as the address of the endpoint, once at the start of the server-relative path.

🔸 EncodeUrl() encodes spaces as %20 and also encodes characters such as # and & that would otherwise end the SourceUrl value early. Do not mix a manually written %20 with EncodeUrl(), the % would be encoded a second time.

3. Show only PDFs.

🔸 Filter the gallery so the viewer is never fed a Word or Excel file, for example by the file name ending in .pdf, or hide the viewer: Visible = EndsWith(Gallery1.Selected.'File name with extension', ".pdf").

4. Keep the fallback on.

🔸 Leave ShowControls set to true. When the control cannot open a document, it offers to open it in the browser, and the control menu has the same option for every external document.

🎉 Result

Selecting a file in the gallery shows the PDF inside the app, built from one text formula. There is no flow to maintain and no base64 round-trip.

🌟 Key Advantages

🔸 No flow: the URL is evaluated in the app, nothing else to build or license.

🔸 Any file in the library: the formula works for every item, including subfolders, because Full Path carries the folder.

🔸 Safe URLs: EncodeUrl() handles spaces and special characters in file names.

⚠️ Good to Know

The PDF viewer is an experimental control with these limitations:

🔸 HTTPS links only, and the link must point directly to the PDF file.

🔸 The file must be accessible anonymously, without authentication.

🔸 The server must allow cross-origin requests from powerapps.com.

🔸 Printing from the control is not supported.

A SharePoint file always requires the user’s sign-in, so download.aspx is outside the supported scenario of this control. Reza’s video shows it working in the browser. Where the control stays blank, the user opens the file in the browser via the control menu, or you offer a button with Launch() on the same URL.

🎥 Video Tutorial

🛠️ FAQ

1. Why doesn’t a SharePoint file link work directly in the PDF Viewer control’s Document property?

A normal SharePoint document link opens the browser-based preview page, an HTML page, not the raw PDF. The PDF viewer control needs a URL that links directly to the PDF file; HTML views and server redirects are not supported.

2. Which formula builds the download.aspx URL for a gallery item?

"https://contoso.sharepoint.com/sites/Projects/_layouts/15/download.aspx?SourceUrl=" & EncodeUrl("/sites/Projects/" & ThisItem.'Full Path'). Full Path is the site-relative path of the file (library and folders included), EncodeUrl() takes care of spaces and special characters.

3. Why does the viewer stay blank for some users?

The PDF viewer (experimental) only supports files that are accessible anonymously and servers that allow cross-origin requests from powerapps.com. A SharePoint file always needs the user’s sign-in, so download.aspx is outside the supported scenario of the control. Set ShowControls to true so users can open the PDF in the browser, or offer a Launch() button.

4. Do I still need a Power Automate flow for this?

No. The download.aspx URL is a text formula in the app. No flow, no premium connector, no base64 round-trip through Power Automate.

🔸 #PowerPlatformTip 159: ‘Direct File Download with Power Apps Launch()’ - the Launch() fallback for files the viewer cannot show.

🔸 #PowerPlatformTip 92: ‘Free PDF Tools in PowerAutomate’ - generate or manipulate the PDFs before you display them with this viewer trick.

🔸 Power Apps Print Directly to a Printer with an API - the control cannot print, this sends the same PDF straight to a printer.


You can see this video here on my blog because I have rated this video with 5 stars in my YouTube video library. This video was automatically posted using PowerAutomate.

This tip is by Marcel Lehmann, Microsoft MVP (Business Applications) and founder of the Power Platform Academy – live Power Platform workshops, free or CHF 49. Join the workshop waitlist to get notified about new dates. For companies that want this implemented for them, see KMUpower – Power Platform consulting & automation for SMEs (DACH).

This post is licensed under CC BY 4.0 by the author.

Microsoft and the Power Platform product names (for example Power Apps, Power Automate, Copilot Studio) are trademarks of the Microsoft group of companies. This is an independent website. It is not operated, sponsored or endorsed by Microsoft.