Concatenate Two PDF Files

Concatenate two PDF files

This article maps directly to the mergePdfDocuments example in PdfFileEditorExamples.java.

Steps

  1. Create a PdfFileEditor instance.
  2. Pass the two input file paths as a string array.
  3. Call concatenate with the array and output file path.
  4. Save the merged PDF.
public static void mergePdfDocuments(Path firstInputFile, Path secondInputFile, Path outputFile) {
    PdfFileEditor pdfEditor = new PdfFileEditor();
    pdfEditor.concatenate(new String[] {firstInputFile.toString(), secondInputFile.toString()}, outputFile.toString());
}