Export from Power Apps to a PDF file

#Office 365, #SharePoint, #PowerApps, #Flow, #MS Graph, #Webcon BPS, #Running & #Technology

Export from Power Apps to a PDF file

This will be my first post on this blog in English. I’ve decided to switch language, because it turned out that writing any manuals or guides in Polish is harder than I previously expected. Almost one year of having this blog and only 8 articles. Maybe it’s time for a new beginning.

Today I would like to show an example how we export content from our Power Apps application or a customized SharePoint form in a simple way to a PDF file.

Power Automate allows us to do it using combination of “Populate a Microsoft Word template” & “Concert Word Document to PDF” actions, but from one side there are some limitations and they are Premium actions, so not everyone will have a chance to use them. So how It might be done using standard actions and connectors?

Assume, that we have a SharePoint were Finance wants to create invoices. All data are stored on a SharePoint lists:

  • Customer details
  • List of all invoices – let’s call it “Invoices”
  • List of all invoices positions/items – let’s call it “InvoicesPositions”

I already have a customized with Power Apps SharePoint list form:

On the left form, I can display all data from “Invoices” list using a Form control. On the right side, I can display all invoice items using a Gallery control with a filtering. What I would like to do is to create a PDF file with all those data when I click “Export to PDF” button.

First of all, I will add an “HTML text” control to create a layout of my PDF file. I can add it on a separate screen, so I will be able to display a preview.

Insite of my html I can add reference to any of my controls used in application, so they will be replaced with values from a SharePoint list. I would like my header to include invoice number (which is a text column) and date (a date time column), in H1 markup I can add:

<h1> Invoice no" & txtTitle.Text & " from " & dtpInvoiceDate.SelectedDate &"</h1>

What with a list of invoice items? The approach is very similar. I can put all items from my gallery (galInvoiceItems) into a table:

<Table><tr><th>Title</th><th>Qty</th><th>Unit price</th><th>VAT rate</th><th>VAT</th><th>Total sum</th></tr>" &
Concat(galIvoiceItems.AllItems,"<tr><td>" & Title & "</td><td>" & Qty &"</td><td>" & 'Unit Price' & "</td><td>" & 'VAT Rate' & "</td><td>" & VAT & "</td><td>" & 'Total Sum' & "</td></tr>" ) &"</Table>

The layout is ready so now let’s move all those data into a PDF file. To do it I will create a Power Automate flow that will be triggered from my app.

At the beginning I need to initialize 3 variables. Two for my file content and name with values that will be passed from Power App. Third one concatenates file name with *.html file extension:

concat(variables('varFileName'),'.html')

Lets create a file. To do it I will use OneDrive actions, as they allows me to create a file and convert it to a PDF. First of all, I’m creating an html file in a temporary folder. Then, performing a convert action – from html to PDF – and saving PDF file in a target folder. At the end I will delete temporary html to avoid making a mess.

Of course it will be good if after creating this file we copy it to a dedicated SharePoint library, send it as an email attachment etc.

My flow is ready, so now all I need to do is just simply configure trigger form my app. On the “Export to PDF” button I select “Power Automate” from action menu and select my flow. The last thing is to set parameters that must be passed from app to flow – file name and file content.

ExportfromPowerAppstoPDF.Run(
    HtmlPDFContent.HtmlText,
    txtTitle.Text
)

Save it, publish and test it! Our PDF is created in our OneDive.

 

Dodaj komentarz

Twój adres email nie zostanie opublikowany. Pola, których wypełnienie jest wymagane, są oznaczone symbolem *