Rotate PDF Pages, the Text or Image with C# or VB.NET

rotate pdf pages images text C#

Let us explore the scenarios related to rotation in PDF documents. You can rotate whole pages or PDF page contents including text or images programmatically using C# or VB.NET in your applications. You will be walking through the following PDF pages, images, or text rotation scenarios with the help of simple and basic examples of PDF rotation features:

PDF Rotation API – Installation

You can efficiently achieve your PDF rotation requirements with Aspose.PDF for .NET API. You can integrate it in your .NET applications by downloading from the Releases section or via NuGet using the following installation command:

Install-Package Aspose.Pdf

Once the API is configured successfully, you can use the Rotation enumeration to select a suitable value of rotation in the clockwise direction.

Rotate All Pages of PDF Document using C#

Let us assume a PDF document created by scanning some documents where all images are scanned at specific angle. Like all pages are rendered upside down and you need to rotate all pages of PDF document in your C# or VB.NET application. Likewise, there could be thousands of related use cases where you need to rotate PDF files. You can rotate all pages of a PDF file with following steps:

  1. Load input PDF document
  2. Iterate through each page
  3. Rotate the pages of PDF with Rotation property
  4. Save output PDF file

The code snippet below shows how to rotate all pages of a PDF file with C# or VB.NET:

Rotate Specific Pages of PDF with C#

The rotation in a PDF document is applied on page level. Therefore, you can also rotate specific pages of PDF file as per your requirements. You only need to choose the page number you want to apply the rotation on. The steps below explain how to rotate certain pages of PDF file:

  1. Load input PDF document
  2. Specify the page numbers to be rotated
  3. Iterate through certain page numbers
  4. Rotate the pages at particular angle
  5. Save output PDF file

The following code snippet elaborates how to rotate specific or certain pages in a PDF document using C# or VB.NET:

Rotate Text on PDF Document using C#

While adding text in PDF documents, you can rotate text at different angles. This text rotation can be more relevant while adding some watermark text in PDF document. Let us add some text at specific coordinates on page and rotate the text diagonally on 45 degrees.

  1. Initialize object of Document class
  2. Add a blank page to the PDF document
  3. Create new TextFragment object
  4. Add text at specific coordinates of the page
  5. Append Text and Save the output PDF file

The code snippet below shows how to rotate text in PDF document using C# or VB.NET:

Rotate Image on PDF using C#

You can rotate image in a PDF document while adding or inserting the image in the PDF file. It can be helpful when you want to update or change the orientation of the image. You can follow these steps to rotate image on a PDF page:

  1. Load input PDF document
  2. Create an instance of ImageStamp class
  3. Set different properties including rotation
  4. Save output PDF file

The following code demonstrates how to rotate image or picture in a PDF document programmatically using C# or VB.NET:


In this article, you have explored how to rotate PDF pages as well as how to rotate text or images/pictures in a PDF document in your .NET applications. You can work with Aspose.PDF for .NET API to call the methods and APIs using C# or VB.NET languages. Moreover, you can reach us at Free Support Forum if you want to discuss any related scenario with us. We will be pleased to guide you!

See Also

Compress, or Optimize PDF Files with Same Quality using Java