In this guide you’ll learn how to combine and merge multiple PDF files to PDF using Power Automate.
For this specific example we build a Flow that will Loop through all the PDF documents once a day in a OneDrive for Business Folder, merge them, and then create a merged PDF document in a different location of our choice.
It’s important to note that in this example we are combining PDFs in OneDrive but you can easily merge multiple PDFs and save them to another destination like Dropbox, Google Drive, SharePoint, or any platform supported by Power Automate.
Before we begin please make sure the following prerequisites are in place:
- An Office 365 subscription with Flow and OneDrive for Business support.
- Muhimbi’s PDF Converter for Power Automate full or free trial subscription.
- Appropriate privileges to create Flows.
- Working knowledge of Microsoft Flow.
Merging PDF using Power Automate (Flow Array Technique)
Here’s how to merge PDFs using Power Automate:
Create a Scheduled Cloud Flow and then enter a suitable Flow Name, with a suitable Start Date and Start Time with a recurrence set to every day.
Insert ‘Initialize variable’ Flow action to store the Merged Contents. Give this action a suitable name and set the fields as follows:
Initial value: *Null
Insert ‘Initialize variable’ Flow action to store the Merged Count.
Initial Value: Null
Add the OneDrive for Business ‘List Files in folder’ Action on the Folder library which contains all the files that need to be Merged.
Insert the ‘Apply to Each Loop’ and add the Output(value) of ‘List Files in folder’ action.
Insert the ‘Add a condition’ action. Insert IsFolder is the Output of “List Files in folder” and you need to set it to “False”.
If the step above, evaluates to True, add the action ‘Get file content using path’
File Path: Path variable which is the output of ‘List Files in folder’.
Insert the ‘Add a condition’ action. Insert Merge Count is the Output of ‘Initialize variable – Merge Count’ and you need to set it to “0”.
If the step above, evaluates to True, add the Muhimbi ‘Convert Document Action’
The Action has two parameters:
Source File Name: Name is the output of ‘List Files in folder’.
Source File Content: File Content is the output of ‘Get file Content using Path’.
- Insert the OneDrive for Business ‘Create file’ action after the ‘Convert document’ action.
The action has three main parameters
Folder Path: The Path of your destination Folder.
File name: You can create a variable for File name if needed. We have hardcoded it to ‘MergedFile.PDF’.
File Content: Processed File Content is the output of ‘Convert Document’ action.
- Now, if the step 8 above, evaluates to False i.e. Merge Count is now not equal to 0, then add the action ‘Get file Content using Path’.
File Path : Enter the same path as in step 10.
Add the Muhimbi ‘Merge documents’ action. It has the following two main parameters
Source File name -1: You can hardcode the File Name ‘MergedFile.pdf’ This file name should be the same as in step 10 and 11.
Source File Content -1: File Content is the output of ‘Get file Content using Path 2’ as in step 11.
Source File name -2: Name is the output of ‘List Files in folder’.
Source File Content -2: File Content is the output of ‘Get file Content using Path’ in step 8.
- Add the OneDrive for Business ‘Create file’ action, under step 12. The Action has three main parameters:
Folder Path: The path of your destination folder.
File name: We have hardcoded it to ‘MergedFile.PDF’.
File Content: Processed File Content is the output of ‘Merge Document’ action.
- Outside ‘Condition 2’ action, add a ‘Set variable’ action. The action has two main parameters:
Name: Select the ‘Merged Count’ variable initialized in step 2.
Value: Set the Value to 1.
You can test this workflow by setting the recurrence “Recurrence” Frequency to ‘Minute’. You can then upload a few PDF documents to the source location, and this will trigger the Flow after a minute and create the merged PDF document in the target.