Orientation Portrait & Paysage
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
Orientation Portrait & Paysage

Orientation Portrait & Paysage

IronPDF for Python prend en charge à la fois l'orientation paysage et portrait pour les nouveaux PDF, et fournit un contrôle de rotation par page pour les documents existants.

Commencer

Pour les nouveaux PDFs, définissez RenderingOptions.PaperOrientation avant d'appeler une méthode de rendu. Pour les PDFs existants, utilisez SetPageRotation ou SetAllPageRotations sur un PdfDocument chargé pour faire pivoter des pages individuelles ou l'ensemble du document.

Comprendre le code

Nouveaux PDF

  • PaperOrientation = PdfPaperOrientation.Landscape : Rend le PDF en orientation paysage. Utilisez Portrait pour revenir à la mise en page verticale par défaut.
  • Fonctionne avec RenderHtmlAsPdf, RenderHtmlFileAsPdf et RenderUrlAsPdf.

PDF existants

  • PdfDocument.FromFile(path) : Charge un fichier PDF existant.
  • Pages[0].PageRotation : Lit la rotation actuelle de la première page (index à partir de zéro).
  • SetPageRotation(PageIndex, Rotation) : Fait pivoter une seule page à l'angle spécifié.
  • SetAllPageRotations(Rotation) : Applique la même rotation à chaque page du document.

Valeurs de rotation

L'enum PdfPageRotation fournit quatre options :

ValeurDegrés
None0°
Clockwise9090°
Clockwise180180°
Clockwise270270°
Apprenez à personnaliser la mise en page PDF avec IronPDF for Python !

Prêt à commencer?

Version :2026.11vient de sortir