Articles in this section
Category / Section

How to rotate the existing PDF document pages?

1 min read

The Syncfusion Essential® PDF is a feature-rich and high performance .NET PDF library used to create, read, and edit PDF documents programmatically without Adobe dependencies. Using this library, you can rotate the existing PDF document page using C#.

Steps to rotate the existing PDF document page programmatically:

  1. Create a new console application project.Screenshot (1337).png
  2. Install the Syncfusion.Pdf.Net.Core NuGet package as a reference to your console application from Nuget.org.
    Screenshot (1568).png
  3. Include the following namespaces in the Program.cs file.

C#

using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf;
  1. Use the following code sample in Program.cs to rotate the existing PDF document page.

C#

// Load the existing PDF document
FileStream inputStream = new FileStream("../../../Input.pdf", FileMode.Open, FileAccess.Read);
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream);

// Get the first page of the document
PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage;

// Rotate the page by 90 degrees
page.Rotation = PdfPageRotateAngle.RotateAngle90;

// Save the modified PDF document
FileStream outputStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.Write);
loadedDocument.Save(outputStream);

// Close the document
loadedDocument.Close(true);

// Close the file streams
inputStream.Close();
outputStream.Close();

A complete working sample can be downloaded from Rotated_the_PDF_document_page.zip

By executing the program, you will get the PDF document as follows.Screenshot (1565).png

Take a moment to peruse the documentation for working with pages, where you will find other options like inserting, removing, and rearranging pages in PDF document, adding margin, and importing pages from the existing PDF document.

Refer here to explore the rich set of Syncfusion Essential® PDF features.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied