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);
}
NuGet Download
Install-Package com.ironsoftware.ironpdf
Attach a Cover Page

Attach a Cover Page

IronPDF's PdfDocument.merge method appends the contents of one PDF document to another PDF document.

When invoked, PdfDocument.merge will add all the pages of PDF document b behind the pages of PDF document a.

This code example shows how developers can use this method to attach cover pages to existing PDF documents. Create the desired cover page for the PDF document using PdfDocument.renderHtmlAsPdf (or load a pre-created one using PdfDocument.fromFile). Then, create (or load) the PDF document that needs the cover page and call PdfDocument.merge to combine them together. Specify the cover page as the first argument of the merge method, followed by the other PDF document.

Observe the use of the setFirstPageNumber on a ChromePdfRenderOptions object to Page 2 within the code example. This allows us to adjust the page numbers of the PDF document to reflect the addition of the cover page prior to the merger. Note that this feature is available only to PDF documents that will be generated on the fly. For existing documents, this page number alteration will need to be done prior to the merger using other means.

The developer can also attach a cover page to a PDF using the PdfDocument.prependPdf method.

Learn more about PdfDocument.merge method
View on GitHub

Ready to Get Started?

Version:2026.8just released

Key in blue circle

Get your free 30-day Trial Key instantly.

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required