How to Set Page Orientation and Rotation

Chaknith related to How to Set Page Orientation and Rotation
Chaknith Bin
September 25, 2023
Updated October 20, 2024
Share:

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.


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");

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
All 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");

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);
Chaknith related to Get Page Rotation
Software Engineer
Chaknith is the Sherlock Holmes of developers. It first occurred to him he might have a future in software engineering, when he was doing code challenges for fun. His focus is on IronXL and IronBarcode, but he takes pride in helping customers with every product. Chaknith leverages his knowledge from talking directly with customers, to help further improve the products themselves. His anecdotal feedback goes beyond Jira tickets and supports product development, documentation and marketing, to improve customer’s overall experience.When he isn’t in the office, he can be found learning about machine learning, coding and hiking.