Easiest Way To Generate A PDF In Power Apps (No HTML)

Easiest Way To Generate A PDF  In Power Apps (No HTML)

With Power Apps you can take the data entered into a form and use it to create PDF. This feature is not available out-of-the-box but I can show you how to build it. To do this we will build a basic form in Power Apps. Then we will design a Word document template and use Power Automate to fill and convert it to PDF. From there you either store the PDF in a SharePoint document library or sent in as an email attachment. In this article I will reveal the simplest way to generate a PDF form in Power Apps.

Table Of Contents:
• Word Document Template Method vs HTML Document MethodIntroduction: The Restaurant Inspection AppSetup The SharePoint ListCreate A Restaurant Inspection FormConfigure The Inspection Form QuestionsSubmit The Restaurant Inspection FormEnable The Developer Tab In Microsoft WordAdd Plain Text Fields To The Word Document TemplateSave The Word Document Template To OneDriveFill-in The Word Document Template With Power AutomateGenerate The PDF Document Using Power Apps & Power Automate



Word Document Template Method vs HTML Document Method

There are are two popular methods to generate a pdf document in Power Apps. The first is to create a fillable Word document template, populate the fields using Power Automate and convert to PDF. The second is to write code for an HTML template directly in Power Apps and use Power Automate to convert HTML to PDF. Here’s why I believe the Word Document template method is best:


Word Document Template Benefits:

  • No-code is required to make a Word document template.
  • Headers, footers and page numbers can used in a Word document template.
  • Text and images will never be cut-off at a page break in a Word document.


Word Document Template Drawbacks:

  • The Word Online connector is a premium connector in Power Automate. However, most organizations have at least one per user license for their Power Platform service account and in my opinion paying to generate PDFs is well worth the price.
  • A repeating section with images is not possible with a word document template. For this feature you will need to use HTML.


Introduction: The Restaurant Inspection App

Staff at a restaurant chain use the Restaurant Inspection App to record the results of a food safety inspection.



When the form above is submitted A PDF showing the inspection results is created and gets sent to the restaurant manager.




Setup The SharePoint List

Create a SharePoint List called Inspections with the following

  • Location (single-line text)
  • InspectionDate (date & time type)
  • InspectedBy (person type)
  • Question1 (yes/no type)
  • Question2 (yes/no type)
  • Question3 (yes/no type)






Create A Restaurant Inspection Form

Open Power Apps Studio and create a new canvas app from blank. Insert a label at the top of the app with the words “Restaurant Inspection” and place a rectangle shape behind it with a blue fill property.



Connect the Inspections SharePoint list to the app.



Then insert an Edit Form to the screen and use the Inspections list as the Datasource.



Layout the form controls as shown in the image below.



Write this code in the DefaultMode property of the form to create a new record when the form is submitted.

FormMode.New




Configure The Inspection Form Questions

The Question1, Question2 and Question3 all use a toggle control with a text value of On or Off. We want the toggle to read yes or no instead.



Use this code in the FalseText property of all the toggles.

"No"




Then write this code in the TrueText property of the toggles.

"Yes"




Set the toggles to start in the No position by changing the Default property of their card to false.

false



Next, we must replace the titles Question 1, Question 2 and Question 3 with a yes-or-no question.



Write this code in the Text property of Title label for Questions 1, 2 and 3.

"Do employees follow proper food handling guidelines?"                 // Question 1
"Are all freezers and refrigerators showing the correct temperature?"  // Question 2
"Is raw meat prepared is a separate area from other food?"             // Question 3




Submit The Restaurant Inspection Form

When the restaurant inspection form is completed the staff member presses the submit button and the results are posted to the Inspections SharePoint list. Submission of a new inspection form triggers the creation of a PDF form.



Insert a button at the bottom of the form and use this code in the OnSelect property.

SubmitForm(frm_Inspection)



Once the Inspection form is submitted we want to show a success notification and clear the form for the next inspection.



Write this code in the OnSuccess property of the Edit Form.

NewForm(frm_Inspection);
Notify("Success: Inspection Form was submitted", NotificationType.Success)




Enable The Developer Tab In Microsoft Word

Next we will create a Word document template. The Word document will be filled in with information from the Power Apps form and converted to a PDF by Power Automate. Open Microsoft Word and begin a new document (.docx). Include a title for each form field and then write some placeholder text below each title.



We need to enable the developer tab in Microsoft Word. Right-click on any tab in the ribbon and select Customize the Ribbon.



Check the developer tab on the right-side menu. Then press OK. The developer tab now appears on the ribbon.




Add Plain Text Fields To The Word Document Template

To fill the form in Power Automate we must implement a fillable plain text control for every form field. Highlight the placeholder value for location and select the plain text control.



Then with the plain text control selected click on Properties.



Fill-in the Title and Tag properties with the name of the field “Location.”



Click on Design mode to see the boundaries of the text input field. The placeholder value should be between the start and end of the plain text control.




Repeat the previous steps for all other fields in the Word document.




Save The Word Document Template To OneDrive

The Word document must be saved to a SharePoint document library or OneDrive to be used by Power Automate. In this tutorial we will save it to OneDrive. Open OneDrive and drag-and-drop the Word document into the root folder.




Fill-in The Word Document Template With Power Automate

A PDF of the Restaurant Inspection form will be generated once the form is submitted in Power Apps. Open Power Automate and create a new automated cloud flow. Name the flow “Generate PDF document” and use When an item is created as the trigger.



Connect the When an item is created trigger to the Inspections SharePoint list.



Add a Populate a Microsoft Word Template action and point it to the Restaurant Inspection Template word document we stored in OneDrive. Fill-in the Word document with information from the newly created record.



The Question 1, 2 and 3 fields have the data type Yes/No in SharePoint but they will display the values true or false in our Word document by default. We must write a Power Automate expression to change the values to yes or no instead. Write these expressions in the Question 1, 2 and 3 fields respectively.

if(triggerOutputs()?['body/Question1'],'Yes','No')
if(triggerOutputs()?['body/Question2'],'Yes','No')
if(triggerOutputs()?['body/Question3'],'Yes','No')




Insert a Create File step to generate the Word document. Use the Body of the previous step as the file content.



Next, use the Convert Word Document to PDF action and supply the location of the newly created file.



The resulting PDF file can be output to a SharePoint document library, stored in a OneDrive folder or sent in an email. In this tutorial we will send an email. Add the Send an email (V2) action and open the advanced properties. Fill-in the Attachments Name property with the filename “InspectionForm.pdf” and populate the Attachments Content property with the PDF document.



We are now done building the flow in Power Automate. Save the flow and turn it on. We are ready to generate the PDF form in Power Apps.




Generate The PDF Document Using Power Apps & Power Automate

It’s time to test the app, flow and word template we’ve created together. Fill-in the Restaurant Inspection form in Power Apps and click Submit.



Once the form is submitted the Power Automate flow will be triggered. It creates a Word document, converts it to a PDF and then sends an email with the PDF attached.



The filled-in PDF attached to the email will look like this.





Questions?

If you have any questions about Easiest Way To Generate PDFs In Power Apps (No HTML) please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion.

Matthew Devaney

Subscribe
Notify of
guest
13 Comments
Oldest
Newest
Inline Feedbacks
View all comments
Francisco Camacho
Francisco Camacho
7 days ago

Great post Mathew, thanks!!! I did something like this using Excel with two Sheets. One hidden for loading data from Power Apps and other with a template where cells are referenced to that data. It works without premium connector and can be converted to PDF also.

Francisco Camacho
Francisco Camacho
5 days ago

Thanks!!! Sorry, but I’m not clear what you mean with repeating data.

aydar sitdikov
aydar sitdikov
5 days ago

Could you tell us in more detail how it is implemented without the premium connector

Francisco Camacho
Francisco Camacho
5 days ago
Reply to  aydar sitdikov

Hi Aydar, you need an Excel file with two sheets stored in SharePoint. One hidden to load data with Power Automate (sheet1) and other (sheet2) with a formulated template referencing the data of sheet1. I will attach 2 pictures to show how it works.

Excel File.png
Francisco Camacho
Francisco Camacho
5 days ago

I’m bringing data from 9 lists from SharePoint, stored by my app in Power Apps. It’s a large flow. Hope it was clear.

Francisco Camacho
Francisco Camacho
5 days ago

The flow.

Flow.png
Francisco Camacho
Francisco Camacho
3 days ago

Matthew, I’m very glad that it was useful.

George Winters
George Winters
6 days ago

Great post! It gave me the courage to try this again. Not easy, but worth it !

Dave
Dave
5 days ago

Thanks Matthew, I was able to follow along up to the point on how to insert fields in the Word doc. I kinda did it, but it wanted me to choose from a list.
How close am I?