IRONSOFTWAREHOME
Split PDFs


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>";
PdfDocument pdf = PdfDocument.renderHtmlAsPdf(html);

// take the first page
PdfDocument page1doc = pdf.copyPage(0);
page1doc.saveAs("Split1.pdf");

// take the pages 2 & 3
var page23doc = pdf.copyPages(1, 2);
page23doc.saveAs("Split2.pdf");
mvn install
Split PDFs

Split PDFs

This code example shows how Java developers can leverage IronPDF's PDF editing functionality to achieve a very common use case: splitting a PDF into smaller PDFs.

Using the copyPages method, developers can quickly produce a new PDF document containing an inclusive set of pages from the source document.

The featured example uses this approach to produce two new PDF documents containing the first page and the second and third pages, respectively, of a newly-rendered PDF document. This preserves the content and structure of the source document in its original form, while copying portions of its contents to separate files - effectively "splitting" the file for all intents and purposes. This approach is useful in situations where the developer must retain the source file in its original form for backup purposes.

A slightly different approach to splitting a PDF document (one that doesn't keep the original file) can be accomplished with the copyPages method in conjunction with the removePages method.

How to Split PDF Files in Java

  1. Install IronPDF Java library to split PDF documents
  2. Import existing PDF or render a new PDF in Java
  3. Split PDF by using the copyPages method to copy the PDF pages to another PdfDocument object
  4. Export the PdfDocument with saveAs method
  5. Perform step 3 in just 1 line of Java code
Learn more about the copyPage method in Java.
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