IRONSOFTWAREHOME
编辑 PDFs

from ironpdf import *

# Instantiate Renderer
renderer = ChromePdfRenderer()

# Join Multiple Existing PDFs into a single document
pdfs = List[PdfDocument]()
pdfs.Add(PdfDocument.FromFile("A.pdf"))
pdfs.Add(PdfDocument.FromFile("B.pdf"))
pdfs.Add(PdfDocument.FromFile("C.pdf"))
pdf = PdfDocument.Merge(pdfs)
pdf.SaveAs("merged.pdf")
 
# Add a cover page
pdf.PrependPdf(renderer.RenderHtmlAsPdf("<h1>Cover Page</h1><hr>"))
 
# Remove the last page from the PDF and save again
pdf.RemovePage(pdf.PageCount - 1)
pdf.SaveAs("merged.pdf")
 
# Copy pages 5-7 and save them as a new document.
pdf.CopyPages(ToPageList([4, 6])).SaveAs("excerpt.pdf")
 
for eachPdf in pdfs:
    eachPdf.Dispose()
pip install ironpdf
编辑 PDFs

编辑 PDFs

IronPDF for Python 提供了一整套简洁的方法,用于合并、重组和提取PDF文档中的页面 —— 合并多个文件、添加封面页、删除页面,只需几行代码即可复制页面子集。

开始

将现有PDF加载到类型化的PdfDocument.Merge以合并它们。 然后,使用CopyPages在保存之前进一步调整文档。

理解代码

  • PdfDocument对象的类型化.NET风格列表。 调用.Add()来追加每个文档。
  • PdfDocument对象返回。
  • PdfDocument,保持页面顺序。
  • SaveAs(path):将文档的当前状态写入磁盘。
  • PdfDocument —— 这里用于添加渲染的HTML封面页作为首页。
  • RemovePage(index):在指定的零基索引位置移除单个页面。 pdf.PageCount - 1 针对最后一页。
  • PdfDocument返回。 ToPageList 将Python索引列表转换为所需的页面列表格式。
  • PdfDocument所持有的底层资源。

零基页面索引

IronPDF中的所有页面操作都使用零基索引。 文档的第5页在索引6处,以此类推。

学习如何使用IronPDF for Python合并和编辑PDF!

准备开始了吗?

版本:2026.10刚刚发布

Key in blue circle

立即获取免费的 30 天试用版密钥。

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF for Python
预约您的免费现场演示
Booking Badge

深受全球数百万工程师信赖

Iron Software 的客户徽标
获取您的无义务咨询
您的资料将始终保密。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
深受全球数百万工程师信赖
立即获取您的免费30 天试用密钥。
无需信用卡或创建账户
Python 模块下载 PDF
using pip 安装

版本: 2026.10

  1. 下载 并安装 Python 3.7+。
  2. 如果尚未安装,请从 pypi.org 安装 pip。
  3. 在终端中执行上述命令。
Python PDF 模块
下载 模块

版本: 2026.10

手动安装到您的项目中

  1. 下载软件包
  2. 在终端中运行此命令
    pip install ironpdf-2026.10-py37-none-win_amd64.whi

$999 起