Delete Pages from PDF

Delete pages from a PDF

The Java sample removes pages 2 and 4 from the source document.

Steps

  1. Create a PdfFileEditor instance.
  2. Build an array with the page numbers to remove.
  3. Call delete with the input file, page array, and output file.
  4. Save the resulting PDF.

Java example

public static void deletePagesFromPdf(Path inputFile, Path outputFile) {
    PdfFileEditor pdfEditor = new PdfFileEditor();
    pdfEditor.delete(inputFile.toString(), new int[] {2, 4}, outputFile.toString());
}