How to Set Page Orientation and Rotation

Page Orientation refers to how a page is laid out, either vertically (portrait) or horizontally (landscape).

Page Rotation is the adjustment of a page's angle, allowing you to change its orientation, which can be useful for correcting alignment or meeting specific viewing preferences. Page angles can be set at 90, 180, and 270 degrees.

IronPDF allows you to specify the orientation as either portrait or landscape during the rendering process. Additionally, you can individually rotate newly rendered or existing PDF pages to angles of 0, 90, 180, or 270 degrees as needed.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPDF with NuGet

    PM > Install-Package IronPdf

  2. Copy the code

    PdfDocument.FromFile("input.pdf").SetAllPageRotations(PdfPageRotation.Clockwise90).SaveAs("rotated.pdf");
  3. Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer


Start using IronPDF in your project today with a free trial.

First Step:
green arrow pointer

Page Orientation Example

Setting the orientation is only possible when generating a PDF document from other formats. You can access the PaperOrientation property from the RenderingOptions class. This property can be set to either portrait or landscape. Portrait is the default page orientation setting.

Code

:path=/static-assets/pdf/content-code-examples/how-to/page-orientation-rotation-orientation.cs
using IronPdf;
using IronPdf.Rendering;

ChromePdfRenderer renderer = new ChromePdfRenderer();

// Change paper orientation
renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Landscape;

PdfDocument pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");

pdf.SaveAs("landscape.pdf");
Imports IronPdf
Imports IronPdf.Rendering

Private renderer As New ChromePdfRenderer()

' Change paper orientation
renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Landscape

Dim pdf As PdfDocument = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page")

pdf.SaveAs("landscape.pdf")
$vbLabelText   $csharpLabel

Output PDF


Page Rotation Example

There are four possible rotation degrees offered by IronPDF:

  • None: 0 degrees or non-rotated document.
  • Clockwise90: 90 degrees rotated clockwise.
  • Clockwise180: 180 degrees rotated clockwise.
  • Clockwise270: 270 degrees rotated clockwise.

Please noteAll page index positions mentioned below follow zero-based indexing.

Set Page Rotation

Use methods below to set the rotation for a single page, multiple pages, or all pages.

  • SetAllPageRotations: Sets the rotation degree for all pages.
  • SetPageRotation: Sets the rotation degree for a single page.
  • SetPageRotations: Sets the rotation degree for a selected list of pages.
:path=/static-assets/pdf/content-code-examples/how-to/page-orientation-rotation-set-rotation.cs
using IronPdf;
using IronPdf.Rendering;
using System.Collections.Generic;

PdfDocument pdf = PdfDocument.FromFile("landscape.pdf");

// Set all pages
pdf.SetAllPageRotations(PdfPageRotation.Clockwise90);

// Set a single page
pdf.SetPageRotation(1, PdfPageRotation.Clockwise180);

// Set multiple pages
List<int> selectedPages = new List<int>() { 0, 3 };
pdf.SetPageRotations(selectedPages, PdfPageRotation.Clockwise270);

pdf.SaveAs("rotatedLandscape.pdf");
Imports IronPdf
Imports IronPdf.Rendering
Imports System.Collections.Generic

Private pdf As PdfDocument = PdfDocument.FromFile("landscape.pdf")

' Set all pages
pdf.SetAllPageRotations(PdfPageRotation.Clockwise90)

' Set a single page
pdf.SetPageRotation(1, PdfPageRotation.Clockwise180)

' Set multiple pages
Dim selectedPages As New List(Of Integer)() From {0, 3}
pdf.SetPageRotations(selectedPages, PdfPageRotation.Clockwise270)

pdf.SaveAs("rotatedLandscape.pdf")
$vbLabelText   $csharpLabel

Output PDF

Get Page Rotation

Use the GetPageRotation method to retrieve the rotation of any particular page in the PDF document. Simply supply the page index to the method.

:path=/static-assets/pdf/content-code-examples/how-to/page-orientation-rotation-get-rotation.cs
using IronPdf;
using IronPdf.Rendering;

PdfDocument pdf = PdfDocument.FromFile("rotatedLandscape.pdf");

PdfPageRotation rotation = pdf.GetPageRotation(1);
Imports IronPdf
Imports IronPdf.Rendering

Private pdf As PdfDocument = PdfDocument.FromFile("rotatedLandscape.pdf")

Private rotation As PdfPageRotation = pdf.GetPageRotation(1)
$vbLabelText   $csharpLabel

Frequently Asked Questions

How can I set the page orientation in a PDF using C#?

You can set the page orientation by using the PaperOrientation property from the RenderingOptions class in IronPDF. This property can be set to either portrait or landscape before rendering the PDF.

What are the possible rotation angles for PDF pages?

IronPDF allows you to rotate PDF pages to four possible angles: 0 degrees (None), 90 degrees (Clockwise90), 180 degrees (Clockwise180), and 270 degrees (Clockwise270).

How do you rotate all pages in a PDF document using C#?

You can rotate all pages in a PDF document by using IronPDF's SetAllPageRotations method, specifying the desired rotation angle (e.g., PdfPageRotation.Clockwise90).

Is it possible to rotate specific pages within a PDF using C#?

Yes, you can rotate specific pages using IronPDF's SetPageRotation method for a single page or SetPageRotations for multiple pages by providing their indices.

How can I determine the current rotation of a PDF page?

You can use the GetPageRotation method in IronPDF to retrieve the rotation angle of a specific page by providing the page index.

What is the default page orientation when creating a new PDF?

The default page orientation when creating a new PDF with IronPDF is portrait.

Do I need any additional libraries to manipulate page orientation and rotation in PDFs?

Yes, you will need to download the IronPDF C# Library to manipulate page orientation and rotation in PDFs.

What is the benefit of using IronPDF for PDF manipulation in C#?

IronPDF provides a comprehensive set of tools for creating, editing, and manipulating PDF documents in C#, including setting page orientation and rotation, which enhances document presentation and aligns with specific viewing preferences.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.