Merge any files from Microsoft Forms into PDF in Power Automate
This article demonstrates how to collect data from fillable Microsoft Forms and combine submitted files into a single PDF with the help of Power Automate (Microsoft Flow). We will use Merge any files into PDF action in Modern engine from the Plumsail Documents connector.
In this example, we will read any files from a Microsoft Forms and HTML file from SharePoint, combine them into one and send the resulting PDF file by email.
Prepare Microsoft form
Before you start building the process, you need to prepare a form for collecting attachments.
Our sample form will collect up to 10 attachments and looks as follows:
Feel free to use this pre-made form template available from the Microsoft Forms library by duplicating it in your account.
If you prefer creating Microsoft Forms from scratch, follow the instructions.
Set up a Documents Process
Now, let us set up the process in Plumsail Documents to generate a PDF file from a Microsoft Form submission.
In this flow, we will merge the HTML file stored in a SharePoint Library, the files received from the form, and the template into a single document. The generated PDF and attachments will then be saved to the SharePoint Library.
If you haven’t registered yet, you can sign up now and enjoy a free 30-day trial.
After registering your account, proceed to create a new process.
We will use a pre-made template and upload the file into the process. Provide a process name, select the output file type, and click Create.
After creating the process, you can edit it online, test the template, adjust the tokens, and either upload a new template or download the existing one.
Next, go to Settings.
In Template settings, you can define the output file name, rename the process if needed, and also add a watermark and document protection.
Learn more about Template settings in our documentation.
Now, when you configured the document template you can Run process to generate documents.
Several triggers are available for starting the process.
For this scenario, click When Microsoft Form is submitted, create document using Plumsail Documents to open the flow in Power Automate.
Create a Power Automate flow
Below, you’ll find the complete Power Automate flow along with step-by-step instructions on how it works:
When a new response is submitted
This is an Automated Cloud Flow with the trigger When a new response is submitted. If this is your first time creating a flow using Microsoft Forms, you’ll be prompted to sign into your Microsoft Forms account from Power Automate:
Get response details
Add the Microsoft Forms Get response details action to retrieve submitted form data for further use in the flow. Select the same Form Id as in the trigger and use the Response Id value from the trigger dynamic content.
Get file content
Add a Get file content action.
This action gets file content of the specified file from the SharePoint document library. You just specify the SharePoint site URL and the path to your file.
You can use any other connector to get files from your system.
Compose
This action is necessary to get the sample JSON payload for the next step - Parse JSON.
In the Inputs field, place the dynamic content representing the attachment field in the Microsoft Form. In our case, it’s Attachment:
You can delete this action once you’ve obtained the sample payload. To retrieve the payload, run the flow by submitting the Microsoft Form with attachments. After the flow runs successfully, copy the Outputs section:
Parse JSON
Add the Parse JSON action, which has two parameters:
Content - select the attachment output Attachment from the Get response details action.
Schema - click Generate from sample and paste the Outputs that you copied from the Compose action. You should receive the schema similar to the example below:
{
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"link": {
"type": "string"
},
"id": {
"type": "string"
},
"size": {
"type": "integer"
},
"referenceId": {
"type": "string"
},
"driveId": {
"type": "string"
},
"status": {
"type": "integer"
}
}
}
}
Initialize variable
Build an array of files to use in the Plumsail Merge any files into PDF action. The array should include the HTML file from the SharePoint library, the PDF attachments from the Microsoft Form, and the Expense Report document generated from the form data.
Enter a variable name varFiles and select the Array type for it:
Start document generation process
Use a Plumsail action, Start document generation process. This action establishes the connection between the Microsoft Form and the Document process we’ve earlier set up in the Plumsail account.
If this is your first time using the Plumsail Documents connector, Power Automate will request a Connection name, an API Key, and Data center location.
You can type any name for the connection, for example Plumsail Documents (production key). Ensure that the selected data center location matches one of your account.
Then, create an API key in your Plumsail Account, copy and paste it into the API key field, and click Create.
Once the connection name is filled out, create an API key in your Plumsail account, copy it and return to Power Automate.
Let’s configure the Start document generation process action. In the Process name field, select Report submission form.
The remaining fields are the ones defined using tokens. For these fields, select the corresponding dynamic content from the Microsoft Form outputs or provide a prepared array in the JSON content field:
Append to array variable
Next, add Append to array variable actions.
These actions will be used to add both the HTML file from the SharePoint library and the Result file from the Start document generation process action to the varFiles array.
When adding the HTML file to the array, use the following expression to convert the HTML content to Base64:
base64(body('Get_file_content_-_HTML'))
Apply to each
Use an Apply to each loop with the following actions:
Use the Get file content action from OneDrive for Business, as form attachments are automatically stored there.
Add the id output from the Parse JSON action.
Then use the Append to array variable action.
In the Name field, select varFiles from the Initialize variable action, and in the Value field, select File content from the previous step output. The File content value represents the PDF attachments from the Microsoft Form.
Merge any files into PDF
Add the Merge any files into PDF action from Plumsail and pass the entire array as input. Select varFiles from Variables. This will merge all files into a single PDF file.
Create file
This is the last action of our flow.
We’ll save the resulting merged PDF to the SharePoint folder. You can choose to save the result file to any other storage system or, for example, send an email with the file attached.
Select the SharePoint site and folder where you’d like to save the files. In the File name field, we added dynamic content Date and Employee from the Get response details action, ensuring each file name is unique. Don’t forget to include the .pdf extension in the file name.
For the File Content, select the Result file from the Merge any files into PDF action. Click Save, and the flow is complete!
Process testing
Let’s put the flow to the test by filling out and submitting the Microsoft Form:
Check the specified SharePoint folder to verify if the PDF document with attachments was successfully saved.
Ultimately, the HTML page, DOCX template, and attachments from the Microsoft Form were correctly merged into a single PDF file:
Conclusion
While the flow may seem a bit long, all the steps are simple to understand and configure. As a result, you’ll have the Microsoft Form, including attachments, converted into one PDF file.