How to Merge and Split PDF Files in Microsoft Power Automate for Desktop

Logo, company name Description automatically generated

Have you ever struggled to merge and split PDF files? In this article we will show you how to easily do so using Microsoft Power Automate for Desktop!

Why might you need to merge or split PDF files?

Maybe you have separate documents from different co-workers that need to be consolidated into one document for reporting or filing purposes. Or maybe you have scanned a big bunch of documents together, but they need to be separate documents.

There are many more reasons you may need to merge/split PDF files, and Microsoft Power Automate for Desktop can help you automate the process.

For those of you who prefer video instructions, you can have a look at the video below. If you prefer to read, just scroll down further for the article.

Skip ahead to the instructions you need:

  1. How to merge PDF files in Microsoft Power Automate for Desktop
  2. How to split PDF files in Microsoft Power Automate for Desktop
  3. How to split PDF files in Microsoft Power Automate for Desktop (unknown number of pages)

How to merge PDF files in Microsoft Power Automate for Desktop

For the merging files portion of the article, we will be using a folder which contains five individual PDF files as an example.

Folder containing PDF files to be merged using Microsoft Power Automate for Desktop

Firstly, we need to use the action “Get files in folders”. Under the “Folder” parameter, choose the right folder from the dropdown menu – in our case, it is the “merge PDF” folder. This action will retrieve all the files in this folder and store it inside a variable called Files which is essentially a list of file objects.

The Get files in folder action in Microsoft Power Automate for Desktop

Next, we will drag and drop the “Merge PDF Files” action, which can be found under PDF actions, into the main workspace. The input parameter in this case would be the “Files” variable

Where to find the Merge PDF files action in Microsoft Power Automate for Desktop

The merge PDF files action in Microsoft Power Automate for Desktop, and the options available

For the “Merged PDF path”, navigate to your desired folder – in our case here, it is the “Merge PDF” folder, and rename the file as “Merged PDF.pdf”. Remember to specify the .pdf extension.

Naming the merged file output

Next, just to be safe, select the “Overwrite” option for “If file exists”.

The Merge PDF files action in Microsoft Power Automate for Desktop, with Merged PDF path entered

Run the flow. Navigating back to your folder, will show that a merged file containing all five individual PDFs has been successfully created!

The resulting merged file found in the folder after running the flow in Microsoft Power Automate for Desktop

How to split PDF files in Microsoft Power Automate for Desktop

To explain splitting PDF files, we will be using a single PDF titled “Sample PDF File”, containing five individual pages.

The folder containing the Sample PDF file.pdf that will be split using Microsoft Power Automate for Desktop

Step 1: Extract PDF file page

Firstly, we will be using the “Extract PDF files pages to new PDF file” action. Under the “PDF file” parameter, specify the PDF file you wish to extract the pages from, and set the “Page selection” as the page you want to extract. For extracted PDF file path, extract the page into a separate PDF file and in this case we have renamed it as “Page 1.pdf”. Remember to always add the file extension .pdf.

Where to find the Extract PDF file pages to new PDF file action in Microsoft Power Automate for Desktop

Naming the resulting extracted PDF file including the .pdf extension

Lastly, select “Overwrite” from the “If file exists” dropdown menu.

The Extract PDF file pages to new PDF file action with the right options selected

After running the flow and navigating to our folder, we can see that we have successfully extracted the first page into a separate pdf file called page1.pdf

The resulting file in the folder after running the flow in Microsoft Power Automate for Desktop

Step 2: Implement a loop to repeat for other pages

Firstly, drag the “Loop” action into the workspace. Since we know there are 5 individual pages, we will set the “Start from” as 1, the “End to” as 5, and the “Increment by” as 1.

Setting up a loop in Microsoft Power Automate for Desktop to repeat the split PDF action steps described previously.

Then, drag your PDF action into the body of your loop. It should look like this:

The Extract PDF file action in the loop we set up in the previous step.

Remove the “Page selection” value which was hardcoded earlier, click on the {x} and choose “LoopIndex” from the dropdown menu.

Extract PDF files action

Changing the page selection option of the Extract PDF files action to %LoopIndex%

Likewise, do the same for the extracted pdf file path instead of hard coding the value to be “Page 1”, we shall use the dynamic value “LoopIndex” instead.

Choosing the %LoopIndex% variable for the extracted PDF file path

Changing the extracted PDF file path of the Extract PDF files action to Page %LoopIndex%.pdf

What this does is loop through the pdf file five times. The starting loop index is 1 and for the first loop we will extract the first page of the pdf file into a new pdf file called “Page 1.pdf” (i.e. Page %LoopIndex%.pdf, where LoopIndex is 1). For the second iteration, the loop index becomes the value of 2 and for this iteration will not extract the first page but will extract the second page and save the second page into a new file called “Page 2.pdf”. This continues so on and so forth until five iterations of the loop have been completed.

Running this flow, will cause the LoopIndex to increment from 1 to 5, and each page has been successfully extracted into five individual PDF files!

How the correct loop set up looks

The resulting split PDF files after successfully running the flow in Microsoft Power Automate for Desktop

However, it is important to note that we coded the loop to increase from 1 to 5 because we knew beforehand that the total pdf files file contains 5 pages. There would be a few change and additional steps to the flow in the scenario where we aren’t aware of how many pages the PDF file contains.

How to split PDF files when number of pages is unknown

We would need to change the “End to” in the Loop dialogue box to an arbitrary large number. In this case, we have set it as 100.

Changing the

We will need to create a label, using the “label” action under “Flow control”. Drag and drop the label to the end of the loop on your workspace.

Where to find the Label action in Microsoft Power Automate for Desktop

Name the label as “OutofBoundsError”.

Naming the label

Click on your “Extract PDF file pages into new PDF file” action, and the “On error” option.

Clicking on the

Under “On error”, choose the option “Continue flow run”, and “Go to label”. Select label as the “OutOfBoundsError”. Click save.

Selecting

Selecting the OutOfBoundsError label

What this does is: Initially we have increased the end loop index to 100, although our PDF file contains only 5 pages. Hence when the loop index reaches the value of 6, which is when it tries to extract page 6 of the PDF file, it will encounter an error as page 6 does not exist. The exception handling has been configured in such a way that when an error is occurred, the flow will jump to the “OutOfBoundsError” label, hence exiting the loop.

Graphical user interface, text, application Description automatically generated

Graphical user interface, text, application Description automatically generated

Now you have successfully managed to split a PDF into individual PDF pages, without hardcoding the number of pages in the PDF!

Automate splitting and merging PDF files in Microsoft Power Automate for Desktop

Now that you’ve learned how to use Microsoft Power Automate for Desktop to automatically split or merge PDF files, it’s time you integrate it into your daily work. We hope you’ve found our tips useful in helping you become more productive.