This Java program merges two PDF files into a single one using Qoppa’s library¬†jPDFAssemble. It is doing so by first opening the 2 PDFs and then appending the second one to the first one and saving the resulting document.

// Load the two PDF documents
PDFAssemble pdfDoc1 = new PDFAssemble ("doc1.pdf", null);
PDFAssemble pdfDoc2 = new PDFAssemble ("doc2.pdf", null);
 
// Append the second document to the first one
pdfDoc1.appendDocument(pdfDoc2);
 
// Save the merged PDF document
pdfDoc1.saveDocument ("merged.pdf");

Download Full Java Sample:
https://www.qoppa.com/files/pdfassemble/guide/sourcesamples/SimpleMerge.java