Tutorials/Power Apps/From Error to Preview: Displaying SharePoint PDFs in Canvas Apps
Power Appsintermediate

From Error to Preview: Displaying SharePoint PDFs in Canvas Apps

Step past the authentication roadblock. Learn how to use Power Automate as a middleman to fetch and display PDFs from SharePoint securely in your Canvas Apps.

NA
Narmer Abader
@narmer · Published June 3, 2026

Every Power Apps maker hits the same wall: you drag out the built-in PDF viewer, point its Document property at a SharePoint file URL, and instead of a beautiful preview you get an error banner — "Couldn't open PDF file". The viewer works on public PDFs, so why does it fail on files you know exist?

The root cause isn't a broken link or a corrupt file. It's an authentication handshake failure. The PDF viewer control runs entirely in the user's browser and does not carry the security tokens SharePoint demands. This guide walks through a production-tested pattern that uses Power Automate as an authenticated proxy to securely deliver PDF content into your app.

How the Proxy Works

The flow acts as an authenticated middleman. It fetches the file from SharePoint using its own service connection, converts the binary into a Data URI, and sends it back to Power Apps. The PDF viewer sees a standard web string and renders it happily, never knowing SharePoint was involved.

Scenario: The Field Audit Review App

A quality assurance team uploads signed PDF audit reports to a SharePoint library named AuditReports. A manager uses a Canvas App to review these reports on a tablet. The app must list every report and display the full PDF content in a side panel without forcing the user to download files or leave the app.

Step 1: Scaffold the App and Data Source

Create a new tablet app from blank and add the AuditReports SharePoint document library as a data source.

Build a split-screen layout:

  • Left side: a vertical gallery named gallery_AuditFiles
  • Right side: a PDF viewer control (it will stay empty until a document is selected)

Set the gallery properties:

PropertyValue
Items'AuditReports'
TemplateSize80
TemplateFillIf(ThisItem.IsSelected, ColorFade(LightSkyBlue, 70%), White)

Add two labels inside the gallery to display file metadata:

  • Label 1 Text property: ThisItem.Title
  • Label 2 Text property: ThisItem.Modified

Step 2: Build the Flow Proxy

Open the Automate menu in Power Apps and select Power AutomateCreate a new flow.

  1. Use the Power Apps V2 trigger. (The V1 trigger does not support the Response action required for this pattern.)
  2. Add a Get file content action from the SharePoint connector.
    • Site Address: your SharePoint site
    • File Identifier: pass the file ID dynamically — we will configure this in the next step.
  3. Add a Response action:
    • Headers: Content-Type = text/plain
    • Body: use the expression below to convert the file content into a Data URI.
textFlow Expression for Response Body
dataUri(base64ToBinary(body('Get_file_content')?['$content']))
  1. Save the flow and name it Proxy_GetFileData.

Back in Power Apps, the flow appears as a new data source. Wire it up in the gallery's OnSelect property.

First, add a file-type guard, because the flow will break if you try to convert a Word document or image into a PDF Data URI.

powerfxGallery OnSelect with File Type Check
If(
  EndsWith(gallery_AuditFiles.Selected.'File name with extension', "pdf"),
  Set(
      varFileData,
      Proxy_GetFileData.Run(gallery_AuditFiles.Selected.Identifier).result
  ),
  Notify("Please select a PDF document.", NotificationType.Warning)
)
Parameter Passing

SharePoint file identifiers can behave differently depending on how the flow receives them. If you encounter a “type mismatch” error, cast the identifier to text: Text(gallery_AuditFiles.Selected.Identifier).

Handling File Refresh Caching

Power Automate caches results. If the user selects the same PDF twice in a row, the flow might not re-run and the PDF viewer won't update. To force a fresh execution, add an optional refreshTimestamp text parameter to the flow trigger. Then call the flow with a dynamic timestamp:

powerfxForce Flow Re-Execution
Set(
  varFileData,
  Proxy_GetFileData.Run(
      gallery_AuditFiles.Selected.Identifier,
      Text(Now())
  ).result
)

Step 4: Display the PDF

Select the PDF viewer control and set its Document property to the variable holding the Data URI.

powerfxPDF Viewer Document Property
varFileData

To keep the UI tidy when nothing is loaded, add a label that only shows when the variable is blank:

powerfxEmpty State Hint
If(
  IsBlank(varFileData),
  "Select a PDF from the list to preview it here.",
  ""
)

Performance and Security Considerations

  • File size limits — A Data URI is Base64-encoded, which inflates the payload by roughly 33%. A 10 MB PDF becomes ~13 MB passing through the flow into the app. This pattern works well for typical office documents but can strain memory and network for PDFs larger than 15 MB. For very large files, consider providing a download link with a temporary access token generated by the flow instead.

  • Data exposure — The file content is converted to a plain-text Data URI and stored in a Power Apps variable. It is scoped to the current user session but should never be written to another data source without encryption. Anyone who obtains the URI string effectively has the file.

  • Delegation — The gallery reads directly from the SharePoint library so delegation works naturally. The EndsWith check runs locally on the single selected item, which is perfectly fine.

  • DLP Policies — If your environment uses Data Loss Prevention (DLP) policies, make sure the SharePoint and Power Apps connectors are permitted in the same business data group. If the flow silently fails to run, DLP is the first place to check.

Troubleshooting Common Issues

Error / SymptomLikely CauseFix
"Type mismatch"Flow parameter expects a string but receives a GUIDWrap the identifier: Text(gallery_AuditFiles.Selected.Identifier)
Flow runs but PDF is blankThe $content path in the expression is wrongOpen the flow history, inspect the Get file content output, and rebuild the dataUri(base64ToBinary(...)) expression
PDF shows old contentFlow cachingAdd the refreshTimestamp parameter pattern shown above
Flow doesn't run at allDLP policy blocks the connectorCheck DLP rules in the Power Platform admin center
Error "Network" or "Timeout"PDF is too large or network is slowReduce file size or use an alternative delivery method (direct download with token)

Conclusion

The Power Automate proxy pattern is one of the most reliable, low-code ways to render authenticated PDFs inside a Canvas App today. It respects SharePoint permissions, stays within the platform boundary, and doesn't require custom connectors or Azure Functions. While Microsoft continues to improve native integration, this technique remains a staple in every maker's toolkit for bridging the authentication gap.

Give it a test with a few small PDFs in your own environment and watch the file-size limit. Once you see that first document render correctly, you will recognise it for the elegant workaround it is.

References