Viewing PDFs from SharePoint within your Power Apps – Master Office 365

In my previous blog in this series, I showcased a demo app whereby a Booking Enquiry for a cruise could be captured in Power Apps by a user, save that information to a List in SharePoint which in turn triggered a Power Automate Flow that then automated the process of generating a booking confirmation PDF document and emailed that document to the person who placed the booking enquiry.

The person who placed the booking could then print out the booking confirmation PDF document they received and bring that with them the day of their booking. The skipper for the cruise boat could then check exactly what was requested when the booking had been placed, for example the number of people that had been booked on the cruise, meals & drinks included or not etc.

That said, the person who placed booking may have forgotten to bring the booking confirmation or perhaps even modified the booking confirmation document they had originally received. Really??? No way ?.

Naturally of course in the real world the skipper would unquestionably have all this information printed out the day of the cruise. Thus for the purposes of this blog at least let’s look at a demo of an app that could nonetheless be useful to them and more importantly talk to something many App Makers have been stumped on within your own apps. Namely viewing PDF documents stored in a document library in SharePoint within your apps.

Demo


Hasn’t this been done before?

Yes, it has been done before!

Notable contributions to the PowerApps community that I am aware of and kudos go out to Paul Culmsee and Ryan McComb.

So how is this blog then different?

I’d like to think that the technique demonstrated in this blog is just about as simple as it can get, short of this functionality become a native feature within PowerApps at least.

The Flow

The Microsoft Power Automate flow that enables this all is as simple as follows:

Step 1 – PowerApps Trigger

You’ll need to create a Flow that you can instantiate from PowerApps. I started with a blank Flow and added the “PowerApps – Trigger” action to begin with.

Step 2 – SharePoint – Get file content using path

For this demo the PDFs I would like to show within my app are located in the default “Shared Documents” library on my Bookings team site. What I would however like to do is pass the file name of the PDF document I wish to display from PowerApps as follows:

And after I click “Ask in PowerApps” this step will look as follows:

Step 3 – PowerApps – Respond to PowerApps

In the file step in the Flow I return the PDF file for the requested document using the “PowerApps – Respond to PowerApps” action.

Choose output type “File“. I named the output variable “PDF


Hang on second (I hear), this doesn’t work…?

Actually it does – you simply need to return the right file information the Power Apps PDF Viewer control understands ?.

For the value of the PDF file parameter to return to PowerApps use the following expression

body('Get_file_content_using_path')['$content']

That’s it – we’re now done with the Flow. That simple!

Power Apps demo app code

All we need to do now is instantiate the Flow from Power Apps and pass in the name of the PDF document you would like to view in the PDF Viewer Control.

In my demo app I’ve added a Gallery control to the Home screen that displays the all the documents in my SharePoint Documents Library. On each row I have an icon that, when clicked, navigates the user to a screen that has a PDF Viewer control, passing the selected item record to the other screen.

Home screen

In the “On Select” property for PDF icon the code snippet is:

Navigate( 
  ViewPDF,
  ScreenTransition.None,
  { selecteditem_v: Home_Bookings_Gallery.Selected }
)

View PDF screen

On the “ViewPDF” screen I have a “PDF Viewer” control to render the PDF document, which I retrieve when the screen is displayed.

On the screen’s “On Visible” property I set a variable “loading_v” which hides the PDF Viewer control whilst the Flow then runs to return the PDF content. When the Flow completes I set the “loading_v” property back to false such the PDF is then visible.

UpdateContext({ loading_v: true });
UpdateContext({
  pdf_v:
  'PowerApps-GetPDFdocument'.Run(
    Concatenate( First( Split( selecteditem_v.Name, "." ) ).Result, ".pdf" )
  )
});
UpdateContext({ loading_v: false })

Per the above snippet, I pass the file name to the Flow and created and use a variable “pdf_v” which will contain the contents of the PDF document returned by the Flow.

The purpose of the “Split” function used in the code above is to remove the file name extenstion of the original document name and thereaafter replace it with a “.pdf” file extenstion name.

Finally on the PDF Viewer control, I set the “Document” property to “pdf_v.pdf” and the “Visible” property to “!loading_v“.

Is it really this easy?

If it is really this simple, why hasn’t anyone tried this before???

Dunno ?

Check out the demo if you’d like to or shout out if you need any help!

Should you decide to test drive the app it’s worth mentioning that I leverage the Graph APIs to two Power Automate flows for the demo app.

One of flows retrieves data from a SharePoint List so you” need to create a corrosponding List as I did per screenshot of List defintion uploaded to the same repository .You can however use a standard SharePoint Connector to any List of your choosing instead of a flow.

The second Flow is really simple and is almost historical give all the historical challenges people have had view PDFs store in SharePoint within their Power Apps.

Source code for demo app

Full Demo App with Source Code! Viewing PDFs from SharePoint within your PowerApps

22 thoughts on “Viewing PDFs from SharePoint within your Power Apps – Master Office 365”

  1. A loft conversion is surely an inexpensive, creative, and easy method
    of increasing the living space which also swells property’s worth.
    Is the flashing (Metal where roof meets home) secured. Water dispersal also prevents soil erosion throughout the edges of your own home.

  2. The cork useful for flooring is harvested from cork trees throughout the Mediterranean. Is the flashing
    (Metal where roof meets home) secured. Hanging artificial plants and plants and artificial
    plants on pots can also be found for you to choose from.

  3. A loft conversion is an inexpensive, creative, as well as simple
    approach to enhancing the home which swells property’s worth.

    Combinations of both light and darker colors
    can supply to gain a classy look. This are certain to get gone the muck and dust,
    making your floors look gleaming and new.

  4. I’m impressed, I must say. Seldom do I come across
    a blog that’s both equally educative and entertaining, and let me tell you, you
    have hit the nail on the head. The problem is something
    not enough folks are speaking intelligently about.
    I am very happy I stumbled across this during my hunt for something regarding this.

  5. Hi. Very interesting content but it’s hard to find masteroffice365.com
    in search results. You are out of google’s top 10, so you can’t expect
    big traffic. You need high quality backlinks to rank in serps.
    And you can get them for free, just search in google: forbesden’s tools

  6. Remarkable things here. I am very happy to see your post.
    Thanks so much and I’m having a look ahead to touch you.
    Will you please drop me a mail?

  7. Good day! I could have sworn I’ve visited this website before but after going through a few
    of the posts I realized it’s new to me. Regardless, I’m definitely
    happy I stumbled upon it and I’ll be bookmarking it and checking back often!

  8. whoah this blog is fantastic i really like studying
    your posts. Stay up the good work! You realize, many people are searching around for this info,
    you could help them greatly.

  9. Hello would you mind sharing which blog platform you’re working with?

    I’m looking to start my own blog soon but I’m having
    a tough time making a decision between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your design seems different then most blogs and I’m looking for something completely unique.
    P.S Apologies for being off-topic but I had to ask!

  10. With havin so much content and articles do you ever run into any issues of plagorism or copyright violation? My website has a lot of completely unique content I’ve either
    written myself or outsourced but it looks like a lot of it is popping it up
    all over the web without my agreement. Do you know any
    techniques to help stop content from being stolen? I’d genuinely appreciate it.

  11. UpdateContext({ loading_v: true });
    UpdateContext({
    pdf_v:
    ‘PowerApps-GetPDFdocument’.Run(
    Concatenate( selecteditem_v._dlc_DocIdUrl_Description,”.pdf” )
    )
    });
    UpdateContext({ loading_v: false })

    The part above doesnt work. Also, Isnt it enough to have just selecteditem_v

    1. Apologizes for the delayed response, but I have rectified this in the blog (hopefully at least 😉)

  12. Good Stuff Brian, great solution for those PDF behind authentication. I have tested and it worked for me.
    Thanks a lot,
    Douglas

  13. This is great Brian, i have been able to post my resource library into my apps and was a fairly simple solution with only a few changes needed.

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.