IRONSOFTWAREHOME
Delete Pages from a PDF


// 4-Paged HTML Document example:
String html = "<p> Hello Iron</p>"
    + "<p> This is 1st Page </p>"
    + "<div style = 'page-break-after: always;' ></div>"
    + "<p> This is 2nd Page</p>"
    + "<div style = 'page-break-after: always;' ></div>"
    + "<p> This is 3rd Page</p>"
    + "<div style = 'page-break-after: always;' ></div>"
    + "<p> This is 4th Page</p>";

PdfDocument pdf = PdfDocument.renderHtmlAsPdf(html);

// Remove a pages 2 & 3.
pdf.removePages(PageSelection.pageRange(1,2));
pdf.saveAs("Page1And4.pdf");
mvn install
Delete Pages from a PDF

Delete Pages from a PDF

Removing PDF Pages with IronPDF PdfDocument.removePages

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

The featured code example uses the removePages method to modify a four-page 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 (effectively 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 to remove a sequential range of pages (pages 4 - 18 of a fictitious 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 IronPDF Java Library
  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 a new document

Here is a Java code example demonstrating these steps:

This concise yet powerful approach of removing pages from a PDF ensures that documents can be easily manipulated according to every specific need.

Explore IronPdf.PdfDocument.RemovePages(PageSelection) Method Documentation
View on GitHub

Ready to Get Started?

Version:2026.8just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

OR
bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required
Java Maven Library for PDF
Install with Maven

Version: 2026.8

<dependency>
   <groupId>com.ironsoftware</groupId>
   <artifactId>ironpdf</artifactId>
   <version>2026.8.2</version>
</dependency>
https://central.sonatype.com/artifact/com.ironsoftware/ironpdf/2026.8.2
or
Java PDF JAR
Download JAR

Version: 2026.8

Manually install into your project