IRONSOFTWAREHOME
直式與橫式排版
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,使用 SetPageRotation 或 SetAllPageRotations 在載入的 PdfDocument 上旋轉個別頁面或整份文件。

理解程式碼

新增PDF

  • PaperOrientation = PdfPaperOrientation.Landscape:以橫向方向渲染PDF。 使用 Portrait 回到預設的正向排版。
  • 可與 RenderHtmlFileAsPdf 及 RenderUrlAsPdf 搭配使用。

現有PDF

  • PdfDocument.FromFile(path):載入現有PDF文件。
  • Pages[0].PageRotation:讀取第一頁的當前旋轉角度(從零開始的索引)。
  • SetPageRotation(PageIndex, Rotation):將單一頁面旋轉至指定角度。
  • SetAllPageRotations(Rotation):對文件中的每一頁應用相同的旋轉。

旋轉值

PdfPageRotation 列舉提供四個選項:

值度數
None0°
Clockwise9090°
Clockwise180180°
Clockwise270270°
學習如何用 IronPDF for Python 自訂PDF版面!

準備開始了嗎?

版本:2026.9剛剛發布

Key in blue circle

立即免費取得 30 天試用金鑰。

Your trial license will be sent to your email address

無任何限制。100% 解鎖。無需信用卡。

OR
bullet_checked無需信用卡或建立帳號無任何限制。100% 解鎖。無需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
預約您的免費即時演示
Booking Badge

全球數百萬工程師的信賴

Iron Software的客戶標誌
獲取您的無義務諮詢
填寫以下表格或發送電子郵件至sales@ironsoftware.com
您的詳細資訊將始終保密。
全球數百萬工程師的信賴
Iron Software的客戶標誌
立即獲取您的30天試用金鑰。
無需信用卡或帳戶建立
PDF的Python模塊下載
使用pip安裝

版本: 2026.9

  1. 下載並安裝Python 3.7+。
  2. 如果尚未安裝,請從 pypi.org 安裝 pip。
  3. 在終端執行上述命令。
Python PDF模塊
下載模塊

版本: 2026.9

手動安裝到您的專案中

  1. 下載套件
  2. 從終端運行此命令
    pip install ironpdf-2026.9-py37-none-win_amd64.whi

從$999起的授權