IRONSOFTWAREHOME
編輯 PDF 檔案

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()
NuGet Download
Install-Package ironpdf
編輯 PDF 檔案

編輯 PDF 檔案

IronPDF for Python提供了一套簡潔的方法,用於合併、重構及提取PDF文件中的頁面——只需幾行程式碼即可合併多個文件、新增封面、刪除頁面,以及複製頁面子集。

入門指南

將現有PDF載入到一個型別化的PdfDocument.Merge以合併它們。 從這裡開始,使用CopyPages進一步對文件進行修改,然後保存。

理解程式碼

  • PdfDocument物件。 調用.Add()以新增每個文件。
  • PdfDocument物件。
  • PdfDocument,保持頁面順序。
  • SaveAs(path):將當前文件狀態寫入磁碟。
  • PdfDocument——這裡用於新增渲染的HTML封面頁作為首頁。
  • RemovePage(index):在指定的零基索引處刪除單個頁面。 pdf.PageCount - 1定位到最後一頁。
  • PdfDocument返回。 ToPageList將Python索引列表轉換為所需的頁面列表格式。
  • PdfDocument持有的底層資源。

零基頁面索引

IronPDF中的所有頁面操作均使用零基索引。 文件的第5頁位於索引6,以此類推。

學習如何使用IronPDF for Python合併和編輯PDF!

準備開始了嗎?

版本:2026.6剛剛發布

Key in blue circle

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

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

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

全球數百萬工程師的信賴

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