Experience with the PDF Viewer has been limited due to its preview status. However, after extensively testing this component for PDF display requirements in Power Apps, I’d like to share my findings.
PDF Viewer (Preview Feature)
As the name suggests, the PDF Viewer is a control designed for displaying PDF files, though it’s currently in preview status. Due to its preview nature, some properties listed in the official documentation may not be available in practice (such as OnSelect).
https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/controls/control-pdf-viewer
- Page navigation
- Zoom in/out capabilities
- Text search functionality
Methods for Specifying PDFs to Display
While the official documentation states that PDFs should be specified using URLs, the actual implementation has several limitations. When using URLs, you must ensure:
- The URL uses HTTPS protocol
- The server hosting the PDF doesn’t require authentication
These restrictions can make the viewer somewhat impractical to use. For example, you cannot directly display PDFs from SharePoint or OneDrive simply by specifying their URLs, as these platforms require authentication.
Here are the recommended alternative methods for specifying PDFs:
Retrieving Data from SharePoint Online Document Library
This method involves using Power Automate to fetch PDF data from SharePoint Online document libraries for display.
Adding as Media
You can embed PDFs as media files in Power Apps, similar to how you would handle image files.
Base64 Data
![](https://ippu-biz.com/wp-content/uploads/2021/04/pdf-base64_004.png)
PDF Viewer Properties
The PDF viewer comes with various properties, and honestly, some of them can be quite challenging to understand 😅
I’ll share my findings from experimenting with these properties.
Note: Since the PDF viewer is still in preview, these features may change without notice.
Document
The Document property specifies which PDF to display. While you typically specify a URL enclosed in double quotes (“”), there are other options:
For PDFs added as media: specify the media name
For Base64-embedded PDFs: specify the Base64 data in double quotes
![](https://ippu-biz.com/wp-content/uploads/2021/04/pdf-base64_004-1024x572.png)
ShowControls
![](https://ippu-biz.com/wp-content/uploads/2021/04/pdfviewer001-1024x610.png)
Zoom and ActualZoom (Read-only)
As the name suggests, the Zoom property controls the magnification/reduction ratio of the PDF display.
- Zoom.FitWidth (value: -1)
- Zoom.FitHeight (value: -2)
- Zoom.FitBoth (value: -3)
![](https://ippu-biz.com/wp-content/uploads/2021/04/pdfviewer002-1024x555.png)
![](https://ippu-biz.com/wp-content/uploads/2021/04/pdfviewer003-1024x590.png)
![](https://ippu-biz.com/wp-content/uploads/2021/04/pdfviewer004-1024x645.png)
The ActualZoom property (read-only) returns the actual zoom percentage. When you set a numerical value in the Zoom property, it returns that value; when using Fit enum values, it returns the actual calculated zoom percentage.
![](https://ippu-biz.com/wp-content/uploads/2021/04/pdfviewer017-1024x653.png)
Page, PageCount (Read-only), and CurrentPage (Read-only)
The Page property allows you to programmatically specify which page to display.
![](https://ippu-biz.com/wp-content/uploads/2021/04/pdfviewer005-1024x606.png)
![](https://ippu-biz.com/wp-content/uploads/2021/04/pdfviewer006-1024x505.png)
![](https://ippu-biz.com/wp-content/uploads/2021/04/pdfviewer007-1024x625.png)
It’s important to note that while setting the Page property will change the viewer’s displayed page, manually navigating in the viewer will not update the Page property.
![](https://ippu-biz.com/wp-content/uploads/2021/04/pdfviewer008-1024x614.png)
FindText
Setting a value (text string) in the FindText property enables text search within the PDF file.
![](https://ippu-biz.com/wp-content/uploads/2021/04/pdfviewer010-1024x561.png)
![](https://ippu-biz.com/wp-content/uploads/2021/04/pdfviewer011-1024x592.png)
While these features are straightforward, the “FindNext” and “FindPrevious” properties have some unique behavioral characteristics.
FindNext, FindPrevious
The FindNext and FindPrevious properties are designed to navigate to the next (or previous) search result, as their names suggest.
![](https://ippu-biz.com/wp-content/uploads/2021/04/pdfviewer012-1024x560.png)
After experimenting, it appears that the navigation to the next (or previous) search result occurs when these property values change to true.
Here’s how you might implement a “Next Search Result” button:
![](https://ippu-biz.com/wp-content/uploads/2021/04/pdfviewer013-1024x477.png)
![](https://ippu-biz.com/wp-content/uploads/2021/04/pdfviewer014-1024x609.png)
![](https://ippu-biz.com/wp-content/uploads/2021/04/pdfviewer015-1024x524.png)
While it’s true that Power Apps can’t directly call control functions, this implementation feels a bit unconventional! 😅
Though I might be using it incorrectly, it’s hard to say for sure given the limited documentation available for the PDF viewer. 🤔
OnStateChange Event
Finally, let’s explore “OnStateChange” – the only action event available in the PDF viewer. While the name suggests it’s triggered when some state changes, it’s not immediately clear which state changes trigger this event.
- Page, CurrentPage
- FindText
- FindNext, FindPrevious
- Zoom, ActualZoom
In essence, this event fires with almost any interaction, whether user-initiated or programmatic.
One practical use case might be verifying whether a user has read through all pages of a document.
For example, you could implement this by storing CurrentPage values in a collection (without duplicates) each time OnStateChange is triggered, then allowing progression to the next screen only when all pages have been viewed.
While we haven’t covered password-protected PDFs in this article, that functionality is also available – perhaps a topic for a future discussion!
コメント