How to rotate a range of pages in a PDF in C# .NET Framework

Cloudmersive
2 min readFeb 23, 2020

--

So we need to rotate a specific subset of pages in a PDF document with C#. No problem. This is going to be much easier than you think, I guarantee it.

We’re going to get this started with installation of our API client. This just means running this command in your Package Manager console:

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

Now that our API can be accessed, our next step is to call EditPdfRotatePageRange and specify our details.

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 EditPdfRotatePageRangeExample{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.var pageStart = 56;  // int? | Page number (1 based) to start rotating pages from (inclusive).var pageEnd = 56;  // int? | Page number (1 based) to stop rotating pages from (inclusive).try{// Rotate a range, subset of pages in a PDF documentbyte[] result = apiInstance.EditPdfRotatePageRange(inputFile, rotationAngle, pageStart, pageEnd);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling EditPdfApi.EditPdfRotatePageRange: " + e.Message );}}}}

Well, that’s it. So easy. We have a whole bunch more APIs that cover all kinds of similar functionality. Name a tricky task, and we’ve probably got an API for that.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet