IRONSOFTWAREHOME
在 PDF 檔案之間複製頁面
from ironpdf import *
 
html_a = """<p> [PDF_A] </p>
        <p> [PDF_A] 1st Page </p>
        <div style='page-break-after: always;'></div>
        <p> [PDF_A] 2nd Page</p>"""

html_b = """<p> [PDF_B] </p>
        <p> [PDF_B] 1st Page </p>
        <div style='page-break-after: always;'></div>
        <p> [PDF_B] 2nd Page</p>"""

renderer = ChromePdfRenderer()

# Create our main document
pdfdoc_a = renderer.RenderHtmlAsPdf(html_a)

# Create and select a page to copy
pdfdoc_b = renderer.RenderHtmlAsPdf(html_b)
page_to_insert = pdfdoc_b.CopyPage(1)

# 3 ways to insert:
pdfdoc_a.AppendPdf(page_to_insert)  # at the end
# or
pdfdoc_a.PrependPdf(page_to_insert)  # at the start
# or
pdfdoc_a.InsertPdf(page_to_insert, 1)  # in the middle

pdfdoc_a.SaveAs("CopiedPages.pdf")
pip install ironpdf
在 PDF 檔案之間複製頁面

在 PDF 檔案之間複製頁面

IronPDF for Python 可以從一個PDF文件中複製頁面並插入到另一個文件的任何位置 - 無論是在結尾、開頭,或者是目標文件內特定的頁面索引。

入門指南

建立或載入兩個PdfDocument物件。 使用CopyPage從源文件中提取特定頁面,然後使用三種插入方法之一將其插入到目標文件中。

理解程式碼

  • PdfDocument中提取單個頁面。 返回一個新的單頁PdfDocument。
  • AppendPdf(page_to_insert):將頁面新增到目標文件的結尾。
  • PrependPdf(page_to_insert):將頁面新增到目標文件的開頭,在所有現有頁面之前。
  • InsertPdf(page_to_insert, index):將頁面插入到目標文件中指定的以零為基礎的位置。 在此範例中,索引1在第一頁後插入頁面。

插入多個頁面

要同時複製和插入多個頁面,請使用InsertPdf方法插入生成的多頁文件。

學習如何使用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起的授權