Merge PDF files in Power Automate

This article demonstrates how to merge PDF files with the help of Power Automate (Microsoft Flow).

In this example, we will read three PDF files from a specific folder, convert these files to PDF, combine them into one and send the resulting PDF file by email.

For instance, it may be useful in a situation when a few employees prepare different sections of a contract at the same time. They load the parts of the contract to a folder, then all files from this folder are merged to form the final document.

So, our source PDF files have to be stored somewhere. Power Automate (Microsoft Flow) has a lot of connectors for different systems. Here are just a few of them:

  • SharePoint

  • Salesforce

  • Box

  • OneDrive

  • Google Drive

  • Dropbox

  • SFTP

  • File System

In this example, we will store our source PDF files in a SharePoint library that we named Source Files Library, but you can get data from other sources. You may use these links to download three sample PDF files: the first, the second, the third. Here is an overview of the complete flow:

Complete flow

The step-by-step configuration is described in further sections of this article.

Flow trigger

You can actually pick any trigger. For example, you can start flow on file creation in a SharePoint document library. We use Manually trigger a flow trigger here to simplify the flow.

Flow trigger

Get files (properties only)

We start with getting properties of all our PDF files stored in a specific folder - Source Files Library. At the next step, we will iterate through the output from this action to get those files contents.

Get files (properties only) action

You can use any other connector to get files from your system.

Initialize variable

We need to prepare an array of files that we will put in Plumsail Documents - Merge PDF action when composing the final document.

Add a new action and search for Variables - Initialize variable action. Enter a name for the variable and choose the Array type for it.

Initialize variable

Get file content using path

Now, you need to add the Get file content using path action to get source PDF files contents.

Click File Path field and add there Folder Path and File name with extension from a menu on the right. This will automatically transform this action into repeating one which will be performed for each file from the source folder.

Get file content using path

Append to array variable

Now, add the Variables - Append to array variable action. Into the Value field, put File content from the output of the previous operation:

Append to array variable

The array of PDF files is ready, now we can move to the main step - merging PDFs into the final document.

Merge PDF

This is an action from Plumsail Documents connector. Add it outside the Apply to each control.

If this is your first time using the Plumsail Documents connector, Power Automate will request the Connection Name and API Key.

Create connection in Power Automate flow

You can type any name for the connection, for example Plumsail Documents.

Once the connection name is filled out, create an API key in your Plumsail Account, copy and paste it into the Access Key field, and then click Create.

Copying an API key from the account

Click a small array icon on the right to switch to the view where you can input an entire array.

Switch to put in entire array

Note

If you do not switch the input mode, you can add the contents of individual files separately.

Add the array of the PDF files to the Content of PDF documents field:

Merge PDF

Send email

Once the result file is generated, we send an email using the Office 365 Outlook - Send an email action. In the Attachments section, we add a name and extension for the merged PDF file and choose the Result file output from the previous Merge PDF action.

Send email

That is all, the flow is configured. Hope, these steps will help to ease the work with documents.