縦向き & 横向き
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
縦向き & 横向き

縦向き & 横向き

IronPDF for Pythonは、新しいPDFファイルに対してランドスケープとポートレートのページオリエンテーションをサポートしており、既存のドキュメントに対してはページごとの回転制御を提供します。

開始方法

新しいPDFについては、レンダーメソッドを呼び出す前にRenderingOptions.PaperOrientationを設定します。 既存のPDFについては、PdfDocumentで個々のページまたはドキュメント全体を回転させます。

コードの理解

新しいPDFファイル

  • PaperOrientation = PdfPaperOrientation.Landscape: PDFを横向きでレンダリングします。 デフォルトの縦向きレイアウトに戻るにはPortraitを使用します。
  • RenderUrlAsPdfで動作します。

既存のPDFファイル

  • PdfDocument.FromFile(path): 既存のPDFファイルをロードします。
  • Pages[0].PageRotation: 最初のページの現在の回転を読み取ります(ゼロベースインデックス)。
  • SetPageRotation(PageIndex, Rotation): 指定された角度に単一のページを回転させます。
  • SetAllPageRotations(Rotation): ドキュメント内のすべてのページに同じ回転を適用します。

回転値

PdfPageRotation列挙型は4つのオプションを提供します。

価値度
None0°
Clockwise9090°
Clockwise180180°
Clockwise270270°
IronPDF for PythonでPDFレイアウトをカスタマイズする方法を学びましょう!

準備はできましたか?

バージョン:2026.11リリースされたばかり