Last active
February 22, 2022 12:35
-
-
Save GroupDocsGists/0d92d118ccada913307231fbf3f741d2 to your computer and use it in GitHub Desktop.
Ways to Split PDF file into Multiple files and Pages in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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); |
Please have a look at the free trial limitations. However, you can avail a temporary license that is actually a time-restricted full license. Follow the steps mentioned in this forum thread.
Apply license as follows:
// Setup license.
License license = new License();
license.SetLicense(@"D:/LicensePath");
If issue persists, please share the complete exception stack trace. Secondly, are you working with multiple GroupDocs APIs (e.g. GroupDocs.Conversion for .NET) in a single project?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, the code is working but complains about the aspose pdf license.
Could you please give advice on how to insert the license to get rid of this problem?
Thanks