Concatenate Multiple PDF Files

Concatenate PDF files

The Java sample merges two files by passing them to the array-based concatenate overload.

Steps

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

To merge more than two files, extend the string array passed to concatenate.