Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ways to Split PDF file into Multiple files and Pages in Java
/*
* Split PDF file by Given Range into Single Page files in Java
*/
// Load the PDF file
Merger merger = new Merger("path/document.pdf");
// Define output file(s) format
String filePathOut = "path/splitPDF_{0}.{1}";
// Define Range to extract as single page documents
SplitOptions splitOptions = new SplitOptions(filePathOut, 3, 7);
// Split PDF according to split options
merger.split(splitOptions);
/*
* Split PDF file by Given Range & Filter (Even/Odd Pages) into Single Page files in Java
*/
// Load the PDF file
Merger merger = new Merger("path/document.pdf");
// Define output file(s) format
String filePathOut = "path/splitPDF_{0}.{1}";
// Define Range & Filter to extract all the ODD Pages in the given Range as single page documents
SplitOptions splitOptions = new SplitOptions(filePathOut, 3, 7, (Integer)RangeMode.OddPages);
// Split PDF according to split options
merger.split(splitOptions);
/*
* Split PDF files into multiple page files in Java
*/
// Load the PDF file
Merger merger = new Merger("path/document.pdf");
// Define output file(s) format
String filePathOut = "path/splitPDF_{0}.{1}";
// Define Splitting Intervals and Split Mode
SplitOptions splitOptions = new SplitOptions(filePathOut, new int[] { 3, 6, 8 }, SplitMode.Interval);
// Split PDF according to given intervals
merger.split(splitOptions);
/*
* Split PDF file into Single Page files in Java
*/
// Load the PDF file
Merger merger = new Merger("path/document.pdf");
// Define output file(s) format
String filePathOut = "path/splitPDF_{0}.{1}";
// Define pages to get extracted as single page document
SplitOptions splitOptions = new SplitOptions(filePathOut, new int[] { 3, 6, 8 });
// Split PDF according to split options
merger.split(splitOptions);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment