IRONSOFTWAREHOME
Attach a Cover Page

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


// Create a Sample Cover Page using RenderHtmlAsPdf
PdfDocument coverPage = PdfDocument.renderHtmlAsPdf("<h1>This is a Cover Page</h1>");
PdfDocument webpage = PdfDocument.renderUrlAsPdf("https://www.nuget.org/packages/IronPdf/");

// Set the page number of the PDF document to be created to 2.
HeaderFooterOptions headerFooterOptions = new HeaderFooterOptions();
headerFooterOptions.setFirstPageNumber(1);
TextHeaderFooter footer = new TextHeaderFooter();
footer.setLeftText("");
footer.setCenterText("Page {page}");
footer.setRightText("");
webpage.addTextFooter(footer, headerFooterOptions);

// Convert a web page's content to a PDF document.
// Merge the cover page with the web page and save the new PDF to the filesystem.
try {
    PdfDocument.merge(coverPage, webpage).saveAs(Paths.get("assets/cover_page_pdf.pdf"));
} catch (IOException e) {
    throw new RuntimeException(e);
}
mvn install
Attach a Cover Page

Attach a Cover Page

IronPDF的PdfDocument.merge方法將一個PDF文件的內容附加到另一個PDF文件中。

當調用時,a的頁面後面。

此程式碼範例顯示如何讓開發者使用此方法將封面頁附加到現有的PDF文件。 使用PdfDocument.fromFile載入已建立的封面)。 然後,建立(或載入)需要封面的PDF文件並呼叫PdfDocument.merge將它們合併在一起。 將封面頁指定為merge方法的第一個參數,接著是其他PDF文件。

觀察在程式碼範例中ChromePdfRenderOptions物件上的使用,以達到頁面2。 這允許我們在合併前調整PDF文件的頁碼以反映封面頁的加入。 請注意,此功能僅適用於即時生成的PDF文件。 對於現有的文件,頁碼的更改需在合併前以其他方式完成。

開發者也可以使用PdfDocument.prependPdf方法將封面頁附加到PDF。

Learn more about PdfDocument.merge method
在 GitHub 查看

準備好開始了嗎?

版本:2026.6剛剛發布

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的Java Maven程式庫
using Maven 安裝

版本: 2026.6

<dependency>
   <groupId>com.ironsoftware</groupId>
   <artifactId>ironpdf</artifactId>
   <version>2026.6.1</version>
</dependency>
https://central.sonatype.com/artifact/com.ironsoftware/ironpdf/2026.6.1
or
Java PDF JAR
下載 JAR

版本: 2026.6

手動安裝到您的專案中