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,在加载的 PdfDocument 上使用 SetPageRotation 或 SetAllPageRotations 旋转单独页面或整个文档。

理解代码

新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 天试用密钥。
无需信用卡或创建账户
Python 模块下载 PDF
using 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 起