Portrait & Landscape Orientation
from ironpdf import *
 
# For NEW PDF Documents use PdfPaperOrientation
# PdfPaperOrientation: To choose Landscape or Portrait Orientation in a new PDF document
renderer = ChromePdfRenderer()
renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Landscape

new_pdf_from_html = renderer.RenderHtmlAsPdf("<h1> Hello World! </h1>")
new_pdf_from_html_file = renderer.RenderHtmlFileAsPdf("example.html")
new_pdf_from_url = renderer.RenderUrlAsPdf("https://ironpdf.com")

# For EXISTING PDFs use PageRotation
# PageRotation: To rotate a PDF page and all of its contents
existing_pdf = PdfDocument.FromFile("old_report.pdf")

# Get rotation value
get_rotation_first_page = existing_pdf.Pages[0].PageRotation

# Rotate specified page
existing_pdf.SetPageRotation(PageIndex=0, Rotation=PdfPageRotation.Clockwise90)

# Rotate ALL pages
existing_pdf.SetAllPageRotations(PdfPageRotation.Clockwise270)
pip install ironpdf
Portrait & Landscape Orientation

Portrait & Landscape Orientation

IronPDF for Python supports both Landscape and Portrait page orientation for new PDFs, and provides per-page rotation control for existing documents.

Getting Started

For new PDFs, set RenderingOptions.PaperOrientation before calling any render method. For existing PDFs, use SetPageRotation or SetAllPageRotations on a loaded PdfDocument to rotate individual pages or the entire document.

Understanding the Code

New PDFs

  • PaperOrientation = PdfPaperOrientation.Landscape: Renders the PDF in landscape orientation. Use Portrait to return to the default upright layout.
  • Works with RenderHtmlAsPdf, RenderHtmlFileAsPdf, and RenderUrlAsPdf.

Existing PDFs

  • PdfDocument.FromFile(path): Loads an existing PDF file.
  • Pages[0].PageRotation: Reads the current rotation of the first page (zero-based index).
  • SetPageRotation(PageIndex, Rotation): Rotates a single page to the specified angle.
  • SetAllPageRotations(Rotation): Applies the same rotation to every page in the document.

Rotation Values

The PdfPageRotation enum provides four options:

ValueDegrees
None0°
Clockwise9090°
Clockwise180180°
Clockwise270270°
Learn to customize PDF layout with IronPDF for Python!

Ready to Get Started?

Version:2026.11just released