Hochformat- & Querformatausrichtung
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
Hochformat- & Querformatausrichtung

Hochformat- & Querformatausrichtung

IronPDF for Python unterstützt sowohl Quer- als auch Hochformat für neue PDFs und bietet eine seitenweise Rotationssteuerung für bestehende Dokumente.

Einstieg

Für neue PDFs setzen Sie RenderingOptions.PaperOrientation, bevor Sie eine Render-Methode aufrufen. Für bestehende PDFs verwenden Sie SetPageRotation oder SetAllPageRotations auf einem geladenen PdfDocument, um einzelne Seiten oder das gesamte Dokument zu drehen.

Den Code verstehen

Neue PDFs

  • PaperOrientation = PdfPaperOrientation.Landscape: Rendert das PDF im Querformat. Verwenden Sie Portrait, um zum Standardlayout im Hochformat zurückzukehren.
  • Funktioniert mit RenderHtmlAsPdf, RenderHtmlFileAsPdf und RenderUrlAsPdf.

Bestehende PDFs

  • PdfDocument.FromFile(path): Lädt eine bestehende PDF-Datei.
  • Pages[0].PageRotation: Liest die aktuelle Drehung der ersten Seite (nullbasierter Index).
  • SetPageRotation(PageIndex, Rotation): Dreht eine einzelne Seite auf den angegebenen Winkel.
  • SetAllPageRotations(Rotation): Wendet die gleiche Drehung auf jede Seite im Dokument an.

Rotationswerte

Das PdfPageRotation-Enum bietet vier Optionen:

WertGrad
None0°
Clockwise9090°
Clockwise180180°
Clockwise270270°
Lernen Sie, das PDF-Layout mit IronPDF for Python anzupassen!

Bereit anzufangen?

Version:2026.11gerade veröffentlicht