Insert Pages into PDF

Insert pages into a PDF

The Java sample inserts pages 1 and 2 from the secondary document after page 2 of the target PDF.

Steps

  1. Create a PdfFileEditor instance.
  2. Choose the insertion point in the target document.
  3. Select the page numbers to copy from the source document.
  4. Call insert with the target file, insertion point, source file, page array, and output file.
  5. Save the updated PDF.

Java example

public static void insertPagesIntoPdf(Path inputFile, Path sampleFile, Path outputFile) {
    PdfFileEditor pdfEditor = new PdfFileEditor();
    pdfEditor.insert(inputFile.toString(), 2, sampleFile.toString(), new int[] {1, 2}, outputFile.toString());
}