IRONSOFTWAREHOME
USING IRONPDF FOR JAVA

How to Split PDF Files in Java

Curtis Chau
Curtis Chau
Updated: August 1, 2026

This article will use IronPDF in Java to split PDF files from a source PDF file.

IronPDF Java PDF Library

IronPDF for Java is a Java library that prioritizes accuracy, ease of use, and speed. It is especially designed for Java and is easy to use when working with PDF documents. It inherits all its functionality from the well-established IronPDF Library for .NET Framework. This makes IronPDF for Java a versatile tool for working with PDF documents in various contexts.

IronPDF offers developers methods to render PDF documents into images and extract text and content from PDFs. Additionally, IronPDF is also capable of rendering charts within PDFs, applying watermarks to PDF files, working with PDF forms, and managing digital signatures programmatically.

Steps to Split PDF Files

Prerequisites for Project Setup

To make IronPDF work with PDFs in a Java Maven project, you will need to make sure that you have the following prerequisites:

  1. JDK (Java Development Kit): You must have a current version of Java running on your computer along with an IDE. If you don't have it, then download the latest JDK from the Oracle website. Use any IDE like NetBeans, Eclipse, or IntelliJ.

  2. Maven: To manage your project and dependencies, Maven is an important tool built specifically for Java projects. Download Maven from the Apache Maven website if you don't have it installed.

  3. IronPDF Java Library: Now you require the IronPDF Java library. This can be done by adding the following dependency to your project's pom.xml file. Maven will automatically download and install it in the project.

    <dependency>
        <groupId>com.ironpdf</groupId>
        <artifactId>ironpdf</artifactId>
        <version>1.0.0</version>
    </dependency>
    XML
  4. Another dependency required is SLF4J. Add the SLF4J dependency in the pom.xml file.

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>2.0.3</version>
    </dependency>
    XML

Once everything is downloaded and installed in your split PDF file Java program, you are ready to use the IronPDF library.

Import Classes

Firstly, import the IronPDF required classes in Java code. Add the following code on top of the "Main.java" file:

import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.License;

import java.io.IOException;
import java.nio.file.Paths;
Java

Now, set your license key using the IronPDF setLicenseKey() method in the Main method:

License.setLicenseKey("Your license key");
Java

Create or Open an Existing PDF File

To split a PDF file into multiple single-page files, it is necessary to either create a PDF file with multiple pages or open a PDF file with multiple pages.

The next code sample will create a four-page PDF that can be used for this demonstration.

// HTML content used to create a four-page PDF
String html = "<p> [PDF With Multiple Pages] </p>"
        + "<p> 1st Page </p>"
        + "<div style='page-break-after: always;'></div>"
        + "<p> 2nd Page</p>"
        + "<div style='page-break-after: always;'></div>"
        + "<p> 3rd Page</p>"
        + "<div style='page-break-after: always;'></div>"
        + "<p> 4th Page</p>";

// Render HTML to a PDF document
PdfDocument pdf = PdfDocument.renderHtmlAsPdf(html);

// Save the PDF document
pdf.saveAs(Paths.get("assets/multiplePages.pdf"));
Java

The PDF Document looks like this:

How to Split PDF Files in Java, Figure 1: Creating New PDFs with IronPDF Creating New PDFs with IronPDF

Open PDF File for Splitting

As an alternative to the previous section, the next code sample uses the [PdfDocument.fromFile](/java/object-reference/api/com/ironsoftware/ironpdf/PdfDocument.html#fromFile(java.nio.file.Path) method to open an existing PDF file using IronPDF.

// Open the existing PDF document
PdfDocument pdf = PdfDocument.fromFile(Paths.get("assets/multiplePages.pdf"));
Java

You can also open a password-protected file by providing a document password as a second argument to the [fromFile](/java/object-reference/api/com/ironsoftware/ironpdf/PdfDocument.html#fromFile(java.nio.file.Path) method.

Split a PDF File into Multiple PDF Files

To split a PDF file, the code is straightforward. Simply copy several pages from the original document using the [copyPage](/java/object-reference/api/com/ironsoftware/ironpdf/PdfDocument.html#copyPage(int) method, as shown below:

// Take the first page
PdfDocument page1Doc = pdf.copyPage(0);
page1Doc.saveAs(Paths.get("assets/split1.pdf"));

// Take the second page
PdfDocument page2Doc = pdf.copyPage(1);
page2Doc.saveAs(Paths.get("assets/split2.pdf"));

// Take the third page
PdfDocument page3Doc = pdf.copyPage(2);
page3Doc.saveAs(Paths.get("assets/split3.pdf"));

// Take the fourth page
PdfDocument page4Doc = pdf.copyPage(3);
page4Doc.saveAs(Paths.get("assets/split4.pdf"));
Java

The PDF file is split by passing the index number as an argument to the copyPage method. Then, save each page in a separate file.

Page 1

Page 1

Page 2

Page 2

Page 3

Page 3

Page 4

Page 4

The [copyPages](/java/object-reference/api/com/ironsoftware/ironpdf/PdfDocument.html#copyPages(int,int) method can also split a PDF by a range of pages. Below, we split the sample PDF evenly in half.

// Copy the first two pages into a new PDF document
PdfDocument halfPages = pdf.copyPages(0, 1);
halfPages.saveAs(Paths.get("assets/halfPages.pdf"));

// Copy the last two pages into another PDF document
PdfDocument endPages = pdf.copyPages(2, 3);
endPages.saveAs(Paths.get("assets/endPages.pdf"));
Java

How to Split PDF Files in Java, Figure 6: Splitting a PDF into Two Halves Splitting a PDF into Two Halves

The complete code example is shown below:

import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.License;

import java.io.IOException;
import java.nio.file.Paths;

public class Main {
    public static void main(String[] args) throws IOException {

        // Set the IronPDF license key
        License.setLicenseKey("Your license key");

        // HTML content to create a four-page PDF document
        String html = "<p> [PDF With Multiple Pages] </p>"
                + "<p> 1st Page </p>"
                + "<div style='page-break-after: always;'></div>"
                + "<p> 2nd Page</p>"
                + "<div style='page-break-after: always;'></div>"
                + "<p> 3rd Page</p>"
                + "<div style='page-break-after: always;'></div>"
                + "<p> 4th Page</p>";

        // Render HTML to a PDF document
        PdfDocument pdf = PdfDocument.renderHtmlAsPdf(html);
        pdf.saveAs(Paths.get("assets/multiplePages.pdf"));

        // Open the existing PDF document
        pdf = PdfDocument.fromFile(Paths.get("assets/multiplePages.pdf"));

        // Split each PDF page into separate documents
        PdfDocument page1Doc = pdf.copyPage(0);
        page1Doc.saveAs(Paths.get("assets/split1.pdf"));
        
        PdfDocument page2Doc = pdf.copyPage(1);
        page2Doc.saveAs(Paths.get("assets/split2.pdf"));
        
        PdfDocument page3Doc = pdf.copyPage(2);
        page3Doc.saveAs(Paths.get("assets/split3.pdf"));

        PdfDocument page4Doc = pdf.copyPage(3);
        page4Doc.saveAs(Paths.get("assets/split4.pdf"));

        // Split the PDF into two halves
        PdfDocument halfPages = pdf.copyPages(0, 1);
        halfPages.saveAs(Paths.get("assets/halfPages.pdf"));

        PdfDocument endPages = pdf.copyPages(2, 3);
        endPages.saveAs(Paths.get("assets/endPages.pdf"));
    }
}
Java

IronPDF can also merge PDF documents effortlessly.

Summary

This article explored how a Java program opens an existing PDF document and splits a PDF file into multiple PDFs using the IronPDF Library.

IronPDF makes the life of a developer a lot easier while working with PDF files in Java. Whether you want to create a new document or work with existing PDF documents, IronPDF helps to achieve all PDF-related tasks with almost a single line of code.

You can use IronPDF in production for free, and it can be licensed for commercial use with flexible options. The IronPDF Lite package starts at $999.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...
Read More

Related Articles

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
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronPdf"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

or download Windows Installer here.

  1. Download and unzip IronPDF to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronPdf.dll"

Licenses from $999