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 can combine the contents of multiple PDF documents. A common use for this feature is attaching cover pages to new or existing PDFs. Other possible uses include bundling related documents together into one file for convenient printing and transport.

The code example above uses the PdfDocument.merge method on two PdfDocument objects that were both rendered from HTML markup. The result of the invocation is a new PdfDocument produced by appending the content of the latter PdfDocument to the end of the former one.

To combine more than three PDF documents, first create a list containing the required PdfDocument objects, and then pass the list as a single argument to the PdfDocument.merge method:

Explore the PdfDocument.merge Method Documentation.
View on GitHub

Ready to Get Started?

Version:2026.10just released