JPedal is a pure Java PDF library which provides developers with several methods to allow for easy splitting of PDF files into multiple new files. The original file is left untouched by this process.
Split PDF into many files
To split a PDF into many files with a set amount of pages per new file, use the following code. The final file contains the remainder of pages so may have fewer pages than the rest.
int pagesPerFile = 3;
PdfManipulator.splitIntoPages(new File("inputFile.pdf"), new File("outputFolder"), pagesPerFile);
If you want to split a password-protected file, add the password as the last argument.
PdfManipulator.splitIntoPages(new File("inputFile.pdf"), new File("outputFolder"), pagesPerFile, "password");
Split PDF into two files
To split a PDF into just two files, use the following code. The first file will contain all pages up to and including pageToSplitAt, and the second file will contain the rest.
int pageToSplitAt = 10;
PdfManipulator.splitInHalf(new File("/path/to/input.pdf"), new File("/path/to/output-folder"), pageToSplitAt);
If you want to split a password-protected file, add the password as the last argument.
PdfManipulator.splitInHalf(new File("/path/to/input.pdf"), new File("/path/to/output-folder"), pageToSplitAt, "password");
Split PDFs with the command line
You may also call the split functions from the command line which allows you to access JPedal from any language or tool.
java -cp jpedal.jar org.jpedal.manipulator.PdfManipulator --splitIntoPages inputFile outputFolder pagesPerFile
java -cp jpedal.jar org.jpedal.manipulator.PdfManipulator --splitInHalf inputFile outputFolder pageToSplitAt