How to rotate all pages in a PDF document in C# .NET Framework

Cloudmersive
2 min readFeb 8, 2020

In today’s chapter of our document editing series, I will be detailing how to rotate PDF pages. I can guarantee that this is the easiest method you will find. Let’s begin.

To get rolling, we need to first install the Document and Data Conversion API Client. This requires pasting this snippet into your Package Manager console.

Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 2.2.0

To proceed, we shall activate EditPdfRotateAllPages using the following excerpt and let the API do the rest of the work.

using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;namespace Example{public class EditPdfRotateAllPagesExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new EditPdfApi();var inputFile = new System.IO.Stream(); // System.IO.Stream | Input file to perform the operation on.var rotationAngle = 56;  // int? | The angle to rotate the page in degrees, must be a multiple of 90 degrees, e.g. 90, 180, 270, or -90, -180, -270, etc.try{// Rotate all pages in a PDF documentbyte[] result = apiInstance.EditPdfRotateAllPages(inputFile, rotationAngle);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling EditPdfApi.EditPdfRotateAllPages: " + e.Message );}}}}

And our rotation is now complete! Not bad, huh? If this pain-free approach works for you, take a look at the rest of the series for more useful functionality.

--

--

Cloudmersive

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