Split PDF using Apache PDFBox

PDF file can be split into many small files using the Apache PDFBox library. Lets see the steps and simple examples on how to Split PDF using Apache PDFBox.

The class mainly used for doing this is org.apache.pdfbox.multipdf.Splitter.

The method that we will be using is Splitter::split(). This method takes PDDocument as a paramter and return a list of PDDocuments by splitting it based on the number of pages by default. You can change the splitting algorithm using the below 3 methods of the Splitter class.
a) setSplitAtPage(int split)
This will tell the splitting algorithm where to split the pages. The default is 1, so every page will become a new document. If it was two then each document would contain 2 pages. If the source document had 5 pages it would split into 3 new documents, 2 documents containing 2 pages and 1 document containing one page.
b) setStartPage(int start)
This will set the start page.
c) setEndPage(int end)
This will set the end page.


We had already merged a PDF in our last post, and we will use that same pdf to split it.

Split PDF using Apache PDFBox

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn