The PDF file format is not natively supported by Java. Therefore, to split a PDF file into multiple PDFs, you will need an external library. This tutorial explains how to split PDF files using JPedal.
Getting Started
- Add JPedal to your class or module path (download the trial jar)
- Create a File handle pointing to the PDF file
- Call one of the methods below from
PdfPageSplit
, and supply a number to determine where to split the PDF
How to split a PDF file into pages
To split a PDF file into individual pages, simply call the following method.
PdfPageSplit.splitAllPages(new File("/path/to/input.pdf"), new File("/path/to/output-folder"));
How to split a PDF file into two files
To split a PDF file into two files, call the following method and provide the page number where you want to split. The first file will contain pages up to and including pageToSplitAt
, and the second file will contain the rest.
PdfPageSplit.splitIn2(new File("/path/to/input.pdf"), new File("/path/to/output-folder"), pageToSplitAt);
How to split a PDF file into multiple files
To split a PDF file into multiple files, call the following method and provide the number of pages you want per file. Each file will contain pagePerNewFile
number of pages, and the final file will contain the remainder.
PdfPageSplit.splitToNPagePDFs(new File("/path/to/input.pdf"), new File("/path/to/output-folder"), pagePerNewFile);
How to split a PDF file that is password protected
JPedal also supports PDF file splitting for password protected files. To do this, provide the password as the last parameter in any of the above methods.
PdfPageSplit.splitAllPages(new File("/path/to/input.pdf"), new File("/path/to/output-folder"), "password");
Before and after
Notice how the original file remains untouched
In this article I showed you how to break large PDF files into multiple documents still in the PDF format. Breaking a PDF into multiple files will have many advantages such as being able to focus on specific content and helping with file size management.
Our software libraries allow you to
Convert PDF to HTML in Java |
Convert PDF Forms to HTML5 in Java |
Convert PDF Documents to an image in Java |
Work with PDF Documents in Java |
Read and Write AVIF, HEIC, WEBP and other image formats |