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
- Rotate All pages of PDF Document using C#
- Rotate Specific Pages of PDF using C#
- Rotate Text on PDF Document using C#
- Rotate Image on PDF using C#
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:
- Load input PDF document
- Iterate through each page
- Rotate the pages of PDF with Rotation property
- 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:
- Load input PDF document
- Specify the page numbers to be rotated
- Iterate through certain page numbers
- Rotate the pages at particular angle
- 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.
- Initialize object of Document class
- Add a blank page to the PDF document
- Create new TextFragment object
- Add text at specific coordinates of the page
- 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:
- Load input PDF document
- Create an instance of ImageStamp class
- Set different properties including rotation
- Save output PDF file
The following code demonstrates how to rotate image or picture in a PDF document programmatically using C# or VB.NET:
Conclusion
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