Skip to content

Power Automate

Merge & Split PDF Files With Power Automate Desktop

Merge & Split PDF Files With Power Automate Desktop Posted by - Matthew Devaney on - May 15, 2022 37 Comments When I’ve want merge or split a PDF file I admi...

Matthew Devaney
Published
Reading time
9 min read

Before you start

Is this guide for you?

Best entry point
Power Automate
Time investment
9 min read

Imported reference from Matthew Devaney's blog for learning purposes. Original: https://www.matthewdevaney.com/merge-split-pdf-files-with-power-automate-desktop/. Author: Matthew Devaney.

Merge & Split PDF Files With Power Automate Desktop Posted by - Matthew Devaney on - May 15, 2022 37 Comments

When I’ve want merge or split a PDF file I admit I’ve often relied upon an free online services which are less than trustworthy or paid hundreds of dollars for a full Adobe Acrobat license. Now that I have Power Automate Desktop installed on my PC I no longer need to do this. Now I am able to write a few simple desktop flows that can merge or split PDF files for free. In this article I will show you how to merge and split PDF files using Power Automate Desktop.

Note: if you would like to follow along with this tutorial you can find the sample files I used here . Table of Contents Organize PDF Files To Merge In A Folder

Merge All PDF Files In A Folder Using A Desktop Flow

Run Desktop Flow To Merge PDF Files In A Folder

Alternate Method: Merge Selected PDF Files With Power Automate Desktop

Run The Desktop Flow To Merge Only Selected PDF Files

Split A PDF File After Every Page Using A Desktop Flow

Repeat The Split PDF Actions For All Pages In The Input PDF File

Add Error Handling To Detect The Final Split PDF Page Run The Desktop Flow To Split A PDF

Alternate Method: Split A PDF Every “N” Pages With A Desktop Flow

Modify The Desktop Flow To Split A PDF At Every N Pages

Run The Desktop Flow To Split A PDF At Every N Pages

Merge PDF Files With Power Automate Desktop

This section will show two methods to merge a PDF file: merging all of the PDF files in a folder and how to merge only the selected files in a folder . Organize PDF Files To Merge In A Folder

Begin by placing all of the PDF files we want to merge into the same folder. Then create a subfolder called Output. The output folder is where the merged PDF will be stored.

In this example, there are 5 PDF files each having 3 pages of text.

Merge All PDF Files In A Folder Using A Desktop Flow

Open Power Automate Desktop and create a new flow called Merge PDF Document .

We want the user to manually select the folder where there are PDFs waiting to be merged.

Add a Display select folder dialog action with the title “Select Folder With PDFs To Merge.”

Next, add a Get files in folder action and point it at the %SelectedFolder% from the previous action. Sort the files by Full name to ensure the PDFs are merged in the same order they appear in the folder.

Then add a Merge PDF files action to join the %Files% found in the folder.

The completed desktop flow to merge PDF files should look like this.

Run Desktop Flow To Merge PDF Files In A Folder

Press play to test the desktop flow. When the dialog box appears select the folder where the PDFs to merge are stored. Then click OK.

Once the desktop flow is finished the merged PDF file will be found in the Output folder.

Open the Merged.pdf file. The merged file has 15 pages. This makes sense because there were originally 5 PDFs each having 3 pages.

Alternate Method: Merge Selected PDF Files With Power Automate Desktop

We can also build the desktop flow to merge only the selected PDF files by a user instead of an entire folder. Start a new desktop flow.

Add a Display select file dialog with the title “Select PDFs to Merge” and enable Allow multiple selection.

A strange quirk of the select files dialog is that it will output the list of files we selected in the opposite order that we chose them. To correct this behaviour we add a Reverse

list action to transform the %SelectedFiles% list.

Then merge the PDF files in the same manner as the previous method.

The desktop flow to merge only selected PDF files in Power Automate Desktop looks like this.

Run The Desktop Flow To Merge Only Selected PDF Files

Give the flow we built a try by pressing the play button. When we do this a select files dialog appears. Choose all of the PDFs to be merged and click Open.

The resulting Merged.pdf file will be found in the Output folder.

Split A PDF File With Power Automate Desktop

This section will show two methods to split a PDF file: how to split a PDF after every page and how to split a PDF after every “n” pages . Split A PDF File After Every Page Using A Desktop Flow

Now that we’ve successfully merged a PDF, let’s learn to do the opposite. We will now take a single PDF file and split it into multiple PDFs – one for each page. Create a new flow in Power Automate Desktop and call it Split PDF Document .

We want the user to select a PDF file to be split. Add a Display select file dialog action with the title “Select PDF To Split.”

Then set another variable called CurrentPage . This variable will be used inside of a loop to track which PDF page is currently being split.

Repeat The Split PDF Actions For All Pages In The Input PDF File

We want to several new PDF files each with a single page split from the original PDF. To do this we will need to use a loop. Add a Loop condition action to the desktop flow.

Set both the First operand and the Second operand to %True%. The loop will continue infinitely until we add a break loop condition later on. Don’t worry about this for now.

Then insert an Extract PDF file page to new PDF file action. Use the %CurrentPage% as the page selection and set the Extracted PDF file path to target the Output folder.

After the PDF file page is extracted increase the %CurrentPage% variable by 1 to go to the next page.

The Power Automate Desktop flow should look like this so far.

Add Error Handling To Detect The Final Split PDF Page

If we go ahead and run the flow it will give an error on the last page. There is no desktop flow action to determine the number of pages in PDF so we will use error handling to break the loop when the %CurrentPage% is out of bounds.

Add a Label action to the bottom of the flow called FinishedPdfSplit .

Then go back to the Extract PDF file pages action and click OnError .

In the Advanced section, choose the Page out of bounds error type and add a new rule . Continue the flow run when an error occurs. Handle the error be going to the label FinishedPdfSplit .

The finished Power Automate Desktop flow to split a PDF should look like this. Run The Desktop Flow To Split A PDF

Press play to give the flow a test. When the select a file dialog PDF appears select a PDF with multiple pages then click Open.

Once the desktop flow is finished running there will page one PDF for each page of the input PDF found in the Output folder.

Alternate Method: Split A PDF Every “N” Pages With A Desktop Flow

What if we wanted to split the PDF every 2 pages, every 3 pages or some other number of pages? The image below shows a modified version of the flow we just built that can split a PDF at any number of pages by updating the EveryNPages variable. Flow actions in green are new actions and flow actions in red are updates of existing actions.

Modify The Desktop Flow To Split A PDF At Every N Pages

Let’s build the desktop flow to split a PDF at every “n” pages together. Beginning at line 4, set a new variable called EveryNPages to a value of 3.

Then add a Create new list action as the first action inside of the loop and name the list %PageRange%. We will use PageRange to determine which PDF pages to split during the current flow loop.

Insert an Add item to list step and add the current page number to the list.

Then place another Add item to list step below it and insert %CurrentPage + EveryNPages – 1%.

After adding both items to the list we can now build the page range. Power Automate Desktop does not have any ability to join numbers and text in a single string by using variable manipulation and the % notation . That is why we are building a list of numbers and using a Join text action to make some text showing the page range (examples: 1-3, 4-6, 7-9).

Setup the Join text action as shown below.

Modify the Extract PDF file pages to new PDF action to use a Page selection of %JoinedText%.

Then change the Increase variable step to Increase by %EveryNPages%.

Finally, at the end of the loop add a Clear list action to reset %PageRange% for the next loop run.

Run The Desktop Flow To Split A PDF At Every N Pages

We are done building the desktop flow to split a PDF at every “n” pages. To test the flow press the play button. A select file dialog will appear. Choose the PDF we want to split.

After the flow is finished running we can see there were 5 files saved to the Output folder.

Each file has exactly 3 pages. This makes sense because we set the variable %EveryNPages% to a value of 3. Did You Enjoy This Article? 😺

Subscribe to get new Power Automate For Desktop articles sent to your inbox each week for FREE Enter your email address Sign Me Up Questions?

If you have any questions about Merge & Split PDF Files With Power Automate For Desktop please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion. PDF Matthew Devaney Power Automate Desktop

Power Automate Desktop Config File Stored In Dataverse Table

Share this

Tagged

Power Automate

Have a Microsoft 365 topic idea?

Share article suggestions, community session ideas, corrections, or real-world scenarios for future nextM365 learning notes.

Suggest a topic

Keep learning Microsoft 365

Explore more practical guides for SharePoint, Power Platform, Copilot Studio, migration, automation, governance, and security.

Continue learning

Next action

What to do next

Browse all tutorials →