Package org.apache.pdfbox.util
Class Splitter
- java.lang.Object
-
- org.apache.pdfbox.util.Splitter
-
public class Splitter extends java.lang.ObjectSplit a document into several other documents.- Version:
- $Revision: 1.7 $
- Author:
- Mario Ivankovits (mario@ops.co.at), Ben Litchfield
-
-
Field Summary
Fields Modifier and Type Field Description protected PDDocumentcurrentDocumentThe current PDF document that contains the splitted page.protected intpageNumberThe current page number that we are processing, zero based.protected PDDocumentpdfDocumentThe source PDF document.
-
Constructor Summary
Constructors Constructor Description Splitter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcreateNewDocument()Create a new document to write the splitted contents to.protected voidcreateNewDocumentIfNecessary()Interface method, you can control where a document gets split by implementing this method.intgetEndPage()This will return the end page.intgetSplitAtPage()This will return how many pages each split document will contain.intgetStartPage()This will return the start page.protected booleanisNewDocNecessary()Check if it is necessary to create a new document.protected voidprocessNextPage(PDPage page)Interface to start processing a new page.protected voidprocessPages(java.util.List pages)Interface method to handle the start of the page processing.voidsetEndPage(int end)This will set the end page.voidsetSplitAtPage(int split)This will tell the splitting algorithm where to split the pages.voidsetStartPage(int start)This will set the start page.java.util.List<PDDocument>split(PDDocument document)This will take a document and split into several other documents.
-
-
-
Field Detail
-
pdfDocument
protected PDDocument pdfDocument
The source PDF document.
-
currentDocument
protected PDDocument currentDocument
The current PDF document that contains the splitted page.
-
pageNumber
protected int pageNumber
The current page number that we are processing, zero based.
-
-
Method Detail
-
split
public java.util.List<PDDocument> split(PDDocument document) throws java.io.IOException
This will take a document and split into several other documents.- Parameters:
document- The document to split.- Returns:
- A list of all the split documents.
- Throws:
java.io.IOException- If there is an IOError
-
setSplitAtPage
public void 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 to then each document would contain 2 pages. So it the source document had 5 pages it would split into 3 new documents, 2 documents containing 2 pages and 1 document containing one page.- Parameters:
split- The number of pages each split document should contain.
-
getSplitAtPage
public int getSplitAtPage()
This will return how many pages each split document will contain.- Returns:
- The split parameter.
-
setStartPage
public void setStartPage(int start)
This will set the start page.- Parameters:
start- the start page
-
getStartPage
public int getStartPage()
This will return the start page.- Returns:
- The start page.
-
setEndPage
public void setEndPage(int end)
This will set the end page.- Parameters:
end- the end page
-
getEndPage
public int getEndPage()
This will return the end page.- Returns:
- The end page.
-
processPages
protected void processPages(java.util.List pages) throws java.io.IOExceptionInterface method to handle the start of the page processing.- Parameters:
pages- The list of pages from the source document.- Throws:
java.io.IOException- If an IO error occurs.
-
createNewDocumentIfNecessary
protected void createNewDocumentIfNecessary() throws java.io.IOExceptionInterface method, you can control where a document gets split by implementing this method. By default a split occurs at every page. If you wanted to split based on some complex logic then you could override this method. For example.protected void createNewDocumentIfNecessary() { if( isPrime( pageNumber ) ) { super.createNewDocumentIfNecessary(); } }- Throws:
java.io.IOException- If there is an error creating the new document.
-
isNewDocNecessary
protected boolean isNewDocNecessary()
Check if it is necessary to create a new document.- Returns:
- true If a new document should be created.
-
createNewDocument
protected void createNewDocument() throws java.io.IOExceptionCreate a new document to write the splitted contents to.- Throws:
java.io.IOException- If there is an problem creating the new document.
-
processNextPage
protected void processNextPage(PDPage page) throws java.io.IOException
Interface to start processing a new page.- Parameters:
page- The page that is about to get processed.- Throws:
java.io.IOException- If there is an error creating the new document.
-
-