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.
How to Set Page Orientation and Rotation
Start using IronPDF in your project today with a free trial.
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")
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 note
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")
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)