How to Rotate PDF Pages in Power Automate

Cloudmersive
5 min readOct 28, 2024

--

When one PDF has pages that are rotated incorrectly, it’s no big deal — we can fix that manually without too much hassle. When dozens of PDFs bear this same issue, however, we have a considerably bigger (and more annoying) problem on our hands.

Thankfully, there’s an easy way we can fix page rotation issues at scale — and without writing any code. We’ll simply use the Cloudmersive PDF connector in Power Automate to set a new rotation angle for the subset of incorrectly rotated pages in our PDF document.

In this article, we’ll walk through a quick example flow in Power Automate that re-rotates a group of pages for several PDF documents stored in the same folder. We’ll create an instant cloud flow in this case so we can have more control over our inputs.

Select the option to create an Instant cloud flow
Trigger the flow manually

In my example flow, I’ll be fixing rotation for the first page of four different PDF documents stored in the same OneDrive folder. My PDFs all currently appear as shown in the below screenshot when opened:

Example — PDF with incorrectly rotated first page

Since we’re making a folder-related action, we’ll first include an action in our flow that retrieves file information from our target folder. If our files live in OneDrive, we can use the List files in folder action, and if our files live in SharePoint, we can use the List folder action.

Use the List files in folder (OneDrive) or List Folder (SharePoint) action to retrieve file Ids and file names

This action retrieves file IDs, file names, and some other file information from our target folder.

In our next step, we’ll add a Get file content action that retrieves file bytes for each PDF in our folder via the Id (File ID) value. Note that Power Automate will automatically place our Get file content action in a For each control to ensure our flow cycles through each set of PDF file bytes.

Use the Get file content action to retrieve PDF file bytes

Within the For each control, we’ll now add in our PDF page rotation action. To find this action, we’ll first search the Power Automate catalogue for Cloudmersive connectors.

Search for the Cloudmersive PDF connector

In the above screenshot, we’ll notice that an action called Rotate a range, subset of pages in a PDF document is included first on my abrreviated actions list. This is the action we’re looking for, but it may not come up immediately for all of us like it did for me.

To find this action, we’ll click “See more,” and we’ll then use a CTRL+F search to locate the correct action.

Search for the Rotate a range, subset of pages in a PDF document action

Once we select this action, we’ll first need to create our connection before we can begin filling request parameters (note that we will need a premium Power Automate license to access Cloudmersive connectors). We can create our connection for free with a free API key, which will give us a limit of 800 API calls per month with zero additional commitments. To get a free API key, we’ll just need to visit the Cloudmersive website and create a free account.

When we’re finished creating our connection & looking at the request parameters, we’ll add PDF file bytes and file names to our request.

Add file bytes and file names to the initial two parameters

In the final three parameters, we’ll determine three important things:

  1. The number of degrees we’d like to rotate our PDF pages (only multiples of 90 degrees are accepted; positive multiples = clockwise page rotation, and negative multiples = counterclockwise page rotation)
  2. The first page number in the set of pages we’d like to rotate (1-based and inclusive)
  3. The final page number in the set of pages we’d like to rotate (1-based and inclusive)

In my example, I’m fixing a 90-degree clockwise rotation for the first page of each PDF document in my folder, so I’m first setting the rotation angle to -90 degrees, and I’m then setting the first and last page numbers to 1.

Add the degree of rotation and decide the range of pages to rotate

In the final step of our flow, we’ll update the original files with the new page rotation. We can use an Update file action to do this, which simply requires our Id (File Id) values and OutputContent from our Rotate pages action.

Use the File Ids and OutputContent to update the original PDFs with new page rotations

We’ll now save our flow and test it. This will update each PDF in our target folder with a new page rotation in the page-range we specified.

Save and test the flow
Check documents for new page rotation

And just like that, we’ve fixed our pesky PDF page rotation problems!

We’ll find this action especially useful in scenarios where two PDF documents with different page rotations are merged. When we know exactly where the page rotation issue begins and ends for multiple documents, we can fix all of them in one fell swoop.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Responses (1)