Leveraging Graph APIs in PowerApps & Flow – PDFs

A few days ago I posted a blog on how to view ‘thumbnail’ images / photos stored in a document library SharePoint within your PowerApps leveraging the Graph v2.0 APIs and a Flow. 

Given that using the Graph APIs to generate thumbnail renditions of photos stored in SharePoint is deemed by Microsoft to be a recommended practice vs the alternate technique I blogged on earlier this year, I spent a couple of days pondering over whether I could equally further enhance my photo demo app to dynamically convert documents stored in SharePoint to PDFs using the Graph APIs similarly in so far as how you could leverage the much less preferred technique using the SharePoint RenderListDataAsStream REST API.

As it turns out you can ?.

Demo – Photo App & PDFs

Demo of how to convert documents on-the-fly stored in SharePoint to PDFs using the Graph v2.0 APIs and render those in PowerApps.

Let’s first see how cool this really is!

So what changed to enable this?

In a nutshell, almost nothing. In my previous blog I posted just a few days ago I shared the demo app showcased and the associated Flow. For this blog the Flow is literally unchanged, whilst in the app I added a PDF icon & link to a screen with a PDF Viewer control to render the PDF version of the associated document when you preview the “so-called” thumbnail image of said document.

Isn’t that awesome or what?

In order to view the PDF document of the thumbnail returned by the Graph API call in the Flow, I quite simply use the Substitute function in the Document property on the PDF Viewer control and replace “transform/thumbnail” with “transform/pdf” for the thumbnail URL returned by the flow. Nothing more!

Is this a recommended practice

Strictly speaking this would unlikely be deemed a recommended practice as this consumes the URL returned by the Graph API thumbnail property for a purpose it wasn’t intended for, namely conversion of documents to PDFs. However it can be equally said that leveraging the RenderListDataAsStream to convert documents to PDFs that can be rendered within your apps is not documented nor intended for that purpose either.

It would nonetheless be reasonable to state this technique would well be at least for now considered a better technique as it is more secure.

Watch for potential enhancements that might perhaps introduce this as native functionality by the PowerApps and Flow teams in the coming months…

Source code for demo app

The demo code for the app as is showcased in this blog can be found on GitHub. Happy app making ?.

1 thought on “Leveraging Graph APIs in PowerApps & Flow – PDFs”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.