Merging documents to PDF using Microsoft Flow

In this post, we will discuss another approach for merging multiple documents into a single PDF using Microsoft Flow. In previous blog posts, we had a look at the Iterative approach and REST API approach to merge documents to PDF.

Both approaches have their own advantages and disadvantages:

  • For the iterative approach we merge one document at a time, as this results in multiple merge requests, the number of operations, and time taken, increases.
  • To overcome the limitation of the iterative approach we used the REST API approach, which combines all operations into a single request, and is not subject to Flow’s 100MB size limitation. However, this only works when the input and output files reside in SharePoint Online.

To overcome the above limitations Muhimbi has come up with an awesome new approach for merging documents to PDF using the recently introduced Microsoft Flow Array technique.

Before we begin. please make sure the following prerequisites are in place:

  • An Office 365 subscription with Flow and OneDrive for Business support.
  • Muhimbi PDF Converter Services Online full, free or trial subscription (Sign up).
  • Appropriate privileges to create Flows.
  • Working knowledge of Microsoft Flow.

Now that we have all the prerequisite in place let’s start building our Microsoft Flow.

In this blog post we will push all the files from a OneDrive for business folder into an array and then pass it to the Muhimbi Merge action, all in one go. Once all the files are merged, we will store the resulting file in a separate folder. Feel free to update the Flow and read the files from a different provider such as DropBox, SharePoint, Google Drive, etc.

So without wasting any more time let’s start building our Flow. From a high-level our Flow looks as follows:

Step 1: For this demo we will use the “When a file is created” OneDrive for Business Trigger. Naturally you can use other triggers as well, whatever is applicable to your scenario.

In the action, specify the path to the Folder to monitor for new files.

Step 2: Add the OneDrive for Business “List Files in folder” Action and specify the folder containing the files to merge.

Step 3: Initialise a variable of type Array and Name it ‘Files’.

Step 4: Add the ‘Apply to each’ loop and set it to the “value” field, output of the OneDrive for Business “List Files in folder” action.

Step 5: Add the “Get file content” action and pass the ‘Id’ value into the File field (Id of OneDrive for Business “List Files in folder” Action action) and set the “Infer Content Type” to ‘No’.

Step 6: Add the “Append to variable” action and specify the following values:

Name: Files


  "source_file_name": @{items('Apply_to_each')?['DisplayName']},
  "source_file_content": @{body('Get_file_content')['$content']}

NOTE: Please enter the expression ‘@{body(‘Get_file_content’)[‘$content’]}’ for the “Source_File_Content” and not just drop entire file.

NOTE: Try to decorate the Processed_File_Content as base64ToBinary() – (screenshot attached).

NOTE : As of June 2020, Microsoft is rolling out a change to how the passing of binary content works for Array variables. Existing flows will continue to work without error, but for newly created flows please pass the regular ‘File Content’ instead of ‘@{body(‘Get_file_content’)[‘$content’]}’. This change is not yet active on all Office 365 tenants, so if one option does not work, try to other. If you get stuck, talk to Muhimbi support.

Step 7: Outside the “Apply to each” loop add the Merge Action, click “Switch to detail inputs for array item” and pass the “Files” variable (the output of the ‘Append to array variable’ action).

Step 8: Add the OneDrive for Business “Create file“ Flow action and configure it with reference to screenshot below.

“Folder Path”: In this demo just hard code it to a path of your choice. Please make sure you don’t use the same path as the input file, or you will create an infinite loop.

“File Name”: For this demo lets just hard code it to “Merged.pdf”

“File Content”: Processed file content (output of Step 7).

That is all there is to it, save your flow and upload a file to the source folder. After a few seconds the merged file will / should show up in the specified output folder.

Subscribe to this blog for the latest updates about SharePoint Online, Microsoft Flow, Power Apps and document conversion and manipulation.

3 thoughts on “Merging documents to PDF using Microsoft Flow

  1. Clavin, I’ve been using this flow for a few weeks now. It’s been working wonderfully and meeting my requirements. Today, I started to get the Byte Limit Error when appending to the Array. The file I am grabbing to merge is just pushing me outside the limits. Any suggestions?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s