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:
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:
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:
{ "source_file_name": @{items('Apply_to_each')?['DisplayName']}, "source_file_content": @{body('Get_file_content')['$content']} }
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.
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 my blog for the latest updates about SharePoint Online, Microsoft Flow, Power Apps and document conversion and manipulation.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.