In this guide you’ll learn how to convert Microsoft Forms to a PDF using a Power Automate.
Steps to convert your Microsoft Form to PDF using Power Automate:
- Create a flow in Power Automate
- Define your action (Convert to PDF)
- Create File (define were your file will be created)
- Publish your workflow
Microsoft Forms provides a quick and easy way to create surveys and questionnaires to collect responses from different people. Even though this is useful, the completed Forms are not easily portable i.e.you cannot send this from one person to another person keeping the “Look and Feel” of the completed Form intact along with any files that have been uploaded to it.
Using Power Automate (Flow) and the Muhimbi PDF Converter, you can merge all the attachments into a single PDF along with the responses and then send that PDF as an email or to write the generated PDF to SharePoint, OneDrive, or anywhere you can send files to using Microsoft Power Automate.
Sample MS Forms with Attachment
Let us consider an example using Power Automate and Muhimbi PDF Converter to convert MS Forms with responses and attachments to PDF and to store them in MS SharePoint or send them to a location supported by Power Automate.
Let us consider a sample MS Form as below for this example:
Note:** The “Sample Patient Questionnaire” has many data entry fields including “Upload File” control to the Form. The “File number limit” has been set to 1, and the “Single file size limit” has been set to 10 MB. The allowed file types are Excel, PowerPoint, PDF, and Image to be uploaded.
Before we start building the workflow, ensure all prerequisites are in place. It is also assumed that the reader has some knowledge of MS Forms and also knowledge of building Workflows using Power Automate.
Make sure the Muhimbi PDF Converter Services Online full, free or trial subscription is installed.
Naturally, in the Microsoft O365, permission to use Power Automate needs to be available to the user as well.
You will need to have the appropriate privileges to create Flows.
Using Power Automate to Convert Forms with Attachment to PDF
As a first step, you can add the ‘When a new response is Submitted’ trigger action specifying the ‘Form Id’ of the Microsoft Form. It will trigger the Flow when a new response is submitted.
Next, you can add ‘Get Response Details’ action specifying the ‘Form Id’ and the ‘Response Id’ of the Microsoft Form. It will trigger the Flow when a new response is submitted.
As a next step we will convert the MS Form to PDF by adding the Muhimbi ‘Convert HTML to PDF’ action. You can copy the HTML code fragment provided below into the ‘Source URL or HTML’ area of the Muhimbi Action and then insert the various list fields in the appropriate places, just before each line’s <br/\element. Your completed code should look like what you see in the screenshot.
Now that we have all our Text questions converted to PDF, let’s work with attachments.
Next, add the ‘Compose’ action to the Flow Canvas and set the Inputs to the field that collects the attachments. In our case, it will be the field ‘Please upload your test results from the clinic’, which is the output from the ‘Get response details’ action and click Save to save the workflow.
Note: You use this action just as a temporary one to get the JSON sample payload for the “Parse JSON” action. This can remove the action after getting the Payload.
- To get the sample payload, fill in the Form and upload a file and submit the Form. This will trigger the Flow.
You can now open the Flow that just ran(succeeded) and expand the ‘Compose’ action, which will look like the screenshot below.
Copy the JSON from ‘OUTPUTS’ of the ‘Compose’ action to a clipboard and then delete the ‘Compose’ action.
- Next, add ‘Parse JSON’ action to the Flow Canvas.
Content: Pass the field ‘Please upload your test results from the clinic’, which is the output from the ‘Get response details’ action, and which is where our attachments are stored.
Schema: In the ‘Parse JSON’ action, click Generate from sample button, which should open a Modal dialog box. You then paste the content from the JSON we copied from Compose action to the Textbox and click Done button.
Note: From the schema you will notice that the Output for the uploaded document is an array of objects that contains the file name, link to item etc. You will need to Parse these JSON objects to use it further in your Flow.
Next, you can add ‘Initialize variable’ action, and set it to a name of ‘Files’ and of type Array.
Next, you can add ‘Get file content for OneDrive’ action to the Flow canvas and add the item “id” output of the ‘Parse JSON’ action.
Note: Flow will automatically add ‘Apply to each’ loop around the ‘Get file content for One Drive’ action.
- Next, within this loop, you can add ‘Append to array variable’ action and specify the following values:
- Name: Files
Next, outside the ‘Apply to each’ loop, add Muhimbi’s ‘Merge documents’ action. Ensure ‘Switch to input entire array’ is active, and pass in the ‘Files’ variable (the output of the ‘Append to array variable’ action).
Finally, you will Merge the Microsoft Form Text Question to the Attachments. To do this, you can add another ‘Merge document’ action, and configure it with reference to the details below:
Note: Do not switch to detail inputs for an Array item in the Muhimbi Merge action.
- Source file name – 1 : InitialQuestion.pdf
- Source file content-1 : Processed file content – output of ‘Convert HTML to PDF’ action.
- Source file name – 2 : Merged.pdf
- Source file content – 2 : Processed file content – output of ‘Merge document 1’ action.
- Finally, you can choose any Send action. In this example, you can use ‘Send an email(V2)’ action to the Flow canvas and configure it with reference to details below:
To: Email Address.
Subject: Patient Questionnaire <You can input any subject of your choice.>
Body: Hi, Patient Questionnaire has been submitted by “Responder’s Email”. Many thanks, Patient Services <You can input any content of your choice here>
Attachment Name: sample.PDF
Attachments Contents: Processed File Content from Merge Document - 2.
Now go back to the sample questionnaire, and answer it, and attach files and click submit.
You will notice that the responses and attachments will be converted to PDF and emailed to the email address chosen in the ‘Send an email(V2)’ action.