IRONSOFTWAREHOME
Join Two or More PDFs

import com.ironsoftware.ironpdf.PdfDocument;  
import java.io.IOException;  
import java.nio.file.Paths;

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

PdfDocument pdfA = PdfDocument.renderHtmlAsPdf(htmlA);
PdfDocument pdfB = PdfDocument.renderHtmlAsPdf(htmlB);
PdfDocument merged = PdfDocument.merge(pdfA, pdfB);

merged.saveAs(Paths.get("assets/merged.pdf"));
mvn install
Join Two or More PDFs

Join Two or More PDFs

IronPDF可以合併多個PDF文件的內容。 此功能的一個常見用途是將封面附加到新的或現有的PDF上。 其他可能的用途包括將相關文件捆綁為一個文件,以便於列印和傳輸。

上面的程式碼範例使用PdfDocument

要合併超過三個PDF文件,首先建立一個包含所需PdfDocument.merge方法:

Explore the PdfDocument.merge Method Documentation.
在 GitHub 查看

準備好開始了嗎?

版本:2026.6剛剛發布

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
預訂您的免費 即時演示
Booking Badge

全球數百萬工程師的信任

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