Merge SharePoint Attachments into a single PDF Document

March 11th 2020
Back to all blogs

As mentioned in a few previous posts, we try to invest as much time as possible into the Power Automate community, which is a fantastic resource for general help/guidance on all elements of the PowerPlatform. A community user recently asked for advice on how to automatically convert SharePoint list item attachments into a single PDF document, and this post is going to detail how to do precisely that!

Build the Flow

For this example, I’m going to trigger the Flow manually… in a real-world scenario, I expect you’d trigger via an update to the SharePoint list item, and when you do this, make sure to add some trigger conditions and logic to control when the list item attachments should be converted, perhaps as part of an approval process.

This example will show you how to retrieve the following item from a SharePoint list and merge the attached documents into a single PDF document.

1. Create a new Flow using the ‘Instant — from blank‘ option

2. Enter a name for the Flow, select the ‘Manually trigger a flow‘ trigger action and click ‘Create.

3. Add a ‘Initialize variable‘ action

3.a. Name: Enter ‘AttachmentsToMerge’

3.b. Type: Select ‘Array

4. Add a SharePoint ‘Get attachments‘ action

4.a. Site Address: Enter the location of the target SharePoint site

4.b. List or Library Name: Select the target SharePoint document library

4. c. Id: Enter the ID of the target SharePoint list item

5. Add a SharePoint ‘Get attachment content‘ action

5.a. Site Address: As per step 4. a.

5. b. List Name: As per step 4. b

5. c. Id: As per step 4. c

5.d. File Identifier: Select the ‘Id‘ property from the ‘Get attachments‘ action

Upon selection, this will automatically place the ‘Get attachment content‘ action into an ‘Apply to each‘ control. This is because the ‘Get attachments‘ action returns an array of documents (one or more)

6. Add an ‘Append to Array Variable‘ action

6.a Name: Select the ‘AttachmentsToMerge’ variable

6. b. Value: Add the following JSON to the ‘Append to array variable‘ variable

   "fileName": ,

6.c. Place the cursor as per the image and select the ‘DisplayName‘ property from the SharePoint ‘Get attachments‘ action

6.d. Place the cursor as per the image:

6.e. Select the ‘Attachment Content‘ property from the SharePoint ‘Get attachment content‘ action

6. f. Completed configuration

The competed JSON value is as follows:

   "fileName": @{items('Apply_to_each')?['DisplayName']},
   "fileContent": @{outputs('Get_attachment_content')?['body']}

7.  Add the Encodian ‘Merge document array to PDF‘ action underneath the ‘Apply to each‘ action

NOTE: The Encodian action will silently convert any non-PDF documents to PDF as part of the merge process

7.a. PDF Filename: Enter a name for the output PDF document

7. b. Click the ‘Switch to input entire array‘ icon

7.c. Pass the ‘AttachmentsToMerge’ variable created in step #3

The configuration to create the merged PDF document is now complete! Next, you must add actions to do something with the PDF document formed from the merged attachments. For this example, I will add the merge file to SharePoint.

8. Add a SharePoint ‘Create file‘ action

8.a. Site Address: Enter the location of the target SharePoint site

8.b. Folder Path: Select the target SharePoint library/folder

8. c. File Name: Select the ‘Filename‘ property from the the ‘Merge document array to PDF‘ action

8.d. File Content: Select the ‘File Content‘ property from the ‘Merge document array to PDF‘ action

Your Flow is complete and should follow this construct… albeit you may have a different trigger action!

Next, test your Flow and validate the created merged PDF document.

NOTE: If you have any issues with the merge action, please raise a ticket with Encodian support. Microsoft is rolling out changes (OpenAPI) to all flow regions, and this can affect how data is processed depending on the trigger action used or when you created the Flow.

Validate the resulting PDF document has been processed correctly:


We hope you’ve found this guide useful, and as ever, please share any feedback or comments – all are welcome!

You can find further documentation and guidance on the Encodian support portal: Merge document array to PDF.

Jay Goodison

Managing Director

Back to all blogs

You might also be interested in...