PPTX DOCX XLSX PDF ODP
Aspose.PDF  Product Family
PDF

PDF Document Page Orientation Solution

Rotate PDF documents with free cross-platform Apps and APIs

How to Rotate PDF Pages

In order to rotate PDF file, we’ll use Aspose.PDF API which is a feature-rich, powerful and easy to use document manipulation API for any platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Rotate PDF documents

<% redaction.feature-section-col1.content-01 %>

  1. Load the PDF with an instance of Document.
  2. Move page upper in order to compensate changing page size.
  3. Set old and new page height.
  4. Setting the page rotation angle.
  5. Save the output PDF file.

System Requirements

Just make sure that you have the following prerequisites.

  • Microsoft Windows or a compatible OS with .NET Framework, .NET Core, and PHP, VBScript, Delphi, C++ via COM Interop.
  • Development environment like Microsoft Visual Studio.
  • Aspose.PDF for .NET DLL referenced in your project.
 

Rotate PDF - C#.

    string dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
    Document doc = new Document(dataDir + "input.pdf");
    foreach (Page page in doc.Pages)
{
    Aspose.Pdf.Rectangle r = page.MediaBox;
    double newHeight = r.Width;
    double newWidth = r.Height;
    double newLLX = r.LLX;
    double newLLY = r.LLY + (r.Height - newHeight);
    page.MediaBox = new Aspose.Pdf.Rectangle(newLLX, newLLY, newLLX + newWidth, newLLY + newHeight);
    // Sometimes we also need to set CropBox (if it was set in original file)
    page.CropBox = new Aspose.Pdf.Rectangle(newLLX, newLLY, newLLX + newWidth, newLLY + newHeight);
    // Setting Rotation angle of page
    page.Rotate = Rotation.on90;
}
    dataDir = dataDir + "ChangeOrientation_out.pdf";
    // Save output file
    doc.Save(dataDir);
 

About Aspose.PDF API

Aspose.PDF API can be used for PDF document manipulation and parsing within applications. One can create, modify, compress, secure, print or save PDF to TXT, HTML, PCL, XFA, XML, XPS, EPUB, TEX, Images and more formats. Aspose.PDF is a standalone API and it does not depend on any software including Adobe Acrobat.

Online PDF Rotation Live Demos

Rotate pages in your PDFs right now by visiting our Live Demos website. The live demo has the following benefits.

  No need to download or setup anything
  No need to write any code
  Just upload your PDF files
  It will be rotated instantly