In an early blog I showcased an awesome solution to display PDF documents stored in a SharePoint Document library in Power Apps using an extraordinarily simple flow. In this blog I will show you how you can view Word documents, PowerPoint presentations and HTML files in Power Apps leveraging the PDF Viewer control with nothing more than a single expression / formula on the Document property of the control.
I haven’t extensively tested all other possible file types however I did test with Excel workbook and Text files and this solution does not work with those file types.
Demo
And now the Solution
In the demo app showcased (and shared later in this blog) I added a Data source connection to a SharePoint Document library containing several Word documents, PowerPoint presentations and HTML files.
Power App Home Screen Controls
In the Power App I added a Gallery control and a PDF Viewer control to the home / landing screen in the app.
Gallery Control
On the Gallery control I set the Items property to the SharePoint Document library Data Source connection and added a few fields to display basic infomation related to each file in the library.
PDF Viewer Control
This is where all the awesomeness happens. All you need to do is set the Document property on the PDF Viewer as follows:
Substitute(
Home_DocumentLibrary_Gallery.Selected.Thumbnail.Small;
"transform/thumbnail";
"transform/pdf"
)
Wrapping Up
Well I did say this was as simple as it gets so no point in waffling any further. By all means test drive the demo app and marvel at the awesomeness ?.
Download the app from the GitHub repository. Import it into your own environment. Remove the existing Data source connection and add a new Data source connection to one of your own Document libraries in SharePoint. Update the Items property on the Gallery control and set it the the Data source connection you’ve added. That’s it, you’re done.
GitHub – Viewing Word, PowerPoint and html files from SharePoint Document Libraries within PowerApps
How could we solve the issue for viewing simple text files?
Wow, this is working for me. Have not tested in all scenarios yet but so far this method actually works. Great job discovering this.
I couldn’t get the sample to work with the current SortByColumns formulae in the Items property. So I changed this eithe 1) MyDocumentLibrary ( no sort) or SortByColumns( MyDocumentLibrary,”{Name}”) . Both work ok and I am now demo happy! Would it be possible to reduce the height of the viewer and have say horizontal scrol bar , similar to the previw popup in SharePoint search .
It works on all files except PDF for me which is really ironic 😀
This was great. I downloaded this but can’t view my pdf files in the pdf viewer. Is this not possible?
Unfortunately this technique doesn’t work when trying to view actual PDF documents that may be stored in your SharePoint Document Libraries.
That said, I have posted another blog that describes an alternate technique you can use to display actual PDF documents stored in SharePoint in your Power Apps. Hopefully that blog will useful to you.
https://masteroffice365.com/viewing-pdfs-from-sharepoint-within-powerapps/
Brian,
This is so simple and elegant.
I have a query. How do you get the powerapp to refresh the gallery view and PDF viewer when a change is made to a document in Sharepoint?
PowerApps keeps seeing the original version, even after data connection refresh. If I make a copy of the amended doc on Sharepoint, then power apps then sees the original and amended version, even though in reality they look exactly the same on Sharepoint.
What, ridiculously simple thing, am I missing to ‘force’ the powerapp to see the real document on Sharepoint?
Best
Colin
Hi Colin,
Thanks for the feedback – glad it’s of use to you!
With regards to you issue displaying documents changed in SharePoint I looked into it and was able to reproduce the behaviour. Turns out it’s because Power Apps caches any documents displayed in the PDF Viewer control for any given Power App session and because the URL doesn’t change even when refreshing the data source, it has no way of knowing when a document may have been changed in SharePoint.
I figured out quite a simple fix though and posted a new blog with regards to how to ensure the latest version of a document is displayed when a user refreshes the data source. Hope it helps!
https://masteroffice365.com/viewing-word-powerpoint-html-files-stored-in-sharepoint-in-power-apps-v2-cached-pdfs/
Cheers,
Brian