Delete Pages from a PDF

Removing one or more pages from a PDF document is trivial task with IronPDF.

The featured code example uses the removePages method to modify a four-paged PDF document (generated on the fly for demonstration purposes). The resulting PDF saved to the local filesystem includes only the first and fourth pages of the original document (in effect, deleting the middle two pages from the document, as expected).

The PageSelection class is used to specify the pages that removePages will delete from a loaded PdfDocument object. Developers can use the class's static pageRange method (as featured above) to remove a sequential range of pages (pages 4 - 18 of a fictious document, for instance). To remove a list of individual pages (not ordered sequentially), provide a List of page indexes to pageRange instead:

How to Delete PDF Pages Using Java

  1. Install Java library to delete PDF pages
  2. Import existing PDF file or render new PDF in Java
  3. Remove pages from PDF with removePages method
  4. Specify the pages to be deleted using PageSelection class
  5. Save the resulting PDF as new document