Download PDF from Power Apps

Download PDF from Power Apps

In this post I will show you how to Download PDF files directly from Power Apps.
It is interesting option for use cases where User should receive result without any delay (waiting for email). For instance after filling in Form or providing some data. I use this method in inspections Apps. Final result of this configuration will generate following result:

Base setup

Firstly I will run through how to create PDF files in Power Automate via One Drive for Business connector:

The combination of three actions allows to create PDF:

  1. Create file
  2. Convert file
  3. Create file

Create HTML file

First Create file is used to generate html file which will be base for the PDF. In File Name after file name add dot and HTM extension. Provide HTML File Content and action will create in User’s One Drive new file.

File Content can be created in Power Automate or like in my case retrieved from Power Apps:

NOTE
In this post I won’t go to details how HTML content is created but please remember that PDF conversion (still in preview) does not support all HTML tags. For instance radio buttons will display in HTML but wont in PDF.

Convert file to PDF

Next action is Convert file we just need to provide from Dynamic Content ID of the HTML file created in previous step and select PDF as target type:

Create PDF file

Last action in this sequence is to again add Create file action and this time as the extension write PDF, for the File Content you need to select File Content from previous action = Convert file.

HINT
I’m creating file in this step to have the ability to download the file but you can already use File Content from Convert file in actions like Create file in SharePoint or as attachment in Send Email:

Link and Response to Power Apps

With above basic setup you are almost ready to Download PDF from Power Apps. Missing bit is to add action Create share link with:

  • Link type of Direct and
  • Link scope Anonymous. Power Automate will generate link which if you would try will download PDF file.

Last but not least is to pass Web URL to Power Apps via Respond action:

Power Apps setup

The Flow is ready but lets look into App how to handle return of the Link so User will Download PDF from Power Apps.

Submit button

First element is prep of the Submit button, OnSelect of the button which will trigger Flow we should add handling of three variables:

UpdateContext({varSpinner:true,varDownload:false});
Set(varLink,
  HI_CreatePDFV2.Run(
          "Demo run of PDF",
          HtmlText1.HtmlText,
          JSON(PenInput1.Image,JSONFormat.IgnoreBinaryData)
  )
);
UpdateContext({varSpinner:false,varDownload:true});

HINT
I’m passing to Power Apps JSON with PenInput if you would like to learn more how to manage that check you Shane Young’s YT here

  • The first variable varSpinner will show and hide spinner GIF so User will know that request is processed.
  • The second variable will hide and show download link when Flow will finish work.
  • The last one is connected with execution of the Flow and thanks to it we will get access to result of the Create Share link action.

Download link

For the download link I use html control and its HtmlText property populated with simple hyperlink tag and connected it with variable which was initialized during Flow execution:

Of course visible property is connected with correct variable in this case varDownload:

Result

When everything is setup correctly your App should work as following and User will see Download PDF from Power Apps in their browser:

Important considerations

There is for sure couple important things not touched in this post but I did not want to make it very long so decided to cover only general idea.
As important considerations I would list:

  1. The presented method does not have error handling implemented.
  2. Files stays in Users One Drive, parallel branch with delay should be added to remove files
  3. Configuration requires for User to have OneDrive connection it can be bypassed but impersonation is material for separate post.

Final thought

I really like this method as it is adding nice UX without a lot of effort and so far stakeholders where I was using it were pleased with it.

Hope you enjoyed the reading and it will adds value to your Power journey. Feel free to leave comment any are welcome.

7 thoughts on “Download PDF from Power Apps

      1. Hi David,
        Thanks for sharing this, but I can’t get the shared link.
        The value returned by the flow is true.
        How can I get the property stringpdf on varlLink, please?

        1. Hi Alberto,
          Thanks for the comment.
          If I understand your question correctly.
          1.) Check if your Flow how the Respond to Power Apps action configured with StringPDF output configured.
          2.) Add to the StringPDF value of Web URL from action Create share link
          3.) In the Power Apps Set the value of the varLink around the flow execution like it was described here: https://365corner.pl/2020/08/21/download-pdf-from-power-apps/#SubmitButton
          4.) If everything worked correctly after the clicking Submit Button variable of the varLink will be populated and by typing varLink.stringpdf you should see in the return link to pdf file.

          Hope this helps you. If not feel free to ask further questions.
          Regards
          Dawid

  1. Hi now there is no option of direct link.thats why iam not able to download the file in system.
    Now what can I do to download the file?

    1. Hi,
      There are at least two approachs to this topic. I will update blog post and tag you after applying the changes. In the end of the day the download is still possible 🙂
      Regards,
      Dawid

Leave a Reply

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