Press "Enter" to skip to content

Merge SharePoint Attachments into a single PDF Document

As mentioned in a few previous posts, we try to invest as much time as we can 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 guidance on how to automatically convert SharePoint list item attachments into a single PDF document, and this post is going to detail how to do exactly that!

Build the Flow

For this example, I’m going to manually trigger the Flow… 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": ,
   "fileContent": 
 } 

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 need to add actions to do something with the PDF document formed from the merged attachments. For this example, I’m just going to 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 the ‘Merge document array to PDF‘ action

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

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

NOTE: If you have any issues with the merge action please raise a ticket with Encodian support. Microsoft are 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:

Finally

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

4 Comments

  1. Aathira Aathira

    I used the above method and the PDF document was created successfully.
    However, the contents within the PDF document was in a different format and hence was not readable.
    Any inputs on how to make the contents within the PDF readable?

    • Jay Gooodison Jay Gooodison

      Hi, can you please raise a ticket with support who will be able to advise. thanks J

  2. EssJay EssJay

    Hi! Loving the Encodian PowerApps connector. Do you have any support for PDF bookmarks through this merge action?

    My individual use case is that I need to merge multiple documents, but I need to know what page they are in the document.

    • Jay Goodison Jay Goodison

      Hi,
      Thanks for the feedback, bookmarking merged documents is very complex… its something we’re working on but it is not avaialble yet.
      HTH
      Jay

Leave a Reply

Your email address will not be published. Required fields are marked *