JPedal provides several methods to allow easy page deletion from PDF files.
These tools will allow you to create a copy of the PDF with the given pages and their content removed from the PDF. The original file is left untouched by this process unless you overwrite it with the output.
Delete Pages from PDF with the Command-Line or another language
java -cp jpedal.jar org.jpedal.manipulator.PdfManipulator --removePage inputFile outputFile pageRange
The pageRange is a page range as defined by SetOfIntegerSyntax
. This range defines the pages to be deleted.
The following example deletes all pages from 2 to 100.
java -cp jpedal.jar org.jpedal.manipulator.PdfManipulator --removePage inputFile outputFile "2-100"
Delete Pages from PDF in Java
final PdfManipulator pdf = new PdfManipulator();
pdf.loadDocument(new File("inputFile.pdf"))
.removePage(new PageRanges("2-100"))
.apply()
.writeDocument(new File("outputFile.pdf"));
pdf.closeDocument();
pdf.reset();