public class Splitter
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private PDDocument |
currentDestinationDocument |
private int |
currentPageNumber |
private java.util.List<PDDocument> |
destinationDocuments |
private int |
endPage |
private MemoryUsageSetting |
memoryUsageSetting |
private PDDocument |
sourceDocument |
private int |
splitLength |
private int |
startPage |
Constructor and Description |
---|
Splitter() |
Modifier and Type | Method and Description |
---|---|
protected PDDocument |
createNewDocument()
Create a new document to write the split contents to.
|
private void |
createNewDocumentIfNecessary()
Helper method for creating new documents at the appropriate pages.
|
protected PDDocument |
getDestinationDocument()
The source PDF document.
|
MemoryUsageSetting |
getMemoryUsageSetting() |
protected PDDocument |
getSourceDocument()
The source PDF document.
|
private void |
processAnnotations(PDPage imported) |
protected void |
processPage(PDPage page)
Interface to start processing a new page.
|
private void |
processPages()
Interface method to handle the start of the page processing.
|
void |
setEndPage(int end)
This will set the end page.
|
void |
setMemoryUsageSetting(MemoryUsageSetting memoryUsageSetting)
Set the memory setting.
|
void |
setSplitAtPage(int split)
This will tell the splitting algorithm where to split the pages.
|
void |
setStartPage(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.
|
protected boolean |
splitAtPage(int pageNumber)
Check if it is necessary to create a new document.
|
private PDDocument sourceDocument
private PDDocument currentDestinationDocument
private int splitLength
private int startPage
private int endPage
private java.util.List<PDDocument> destinationDocuments
private int currentPageNumber
private MemoryUsageSetting memoryUsageSetting
public MemoryUsageSetting getMemoryUsageSetting()
public void setMemoryUsageSetting(MemoryUsageSetting memoryUsageSetting)
memoryUsageSetting
- public java.util.List<PDDocument> split(PDDocument document) throws java.io.IOException
document
- The document to split.java.io.IOException
- If there is an IOErrorpublic void setSplitAtPage(int split)
split
- The number of pages each split document should contain.java.lang.IllegalArgumentException
- if the page is smaller than one.public void setStartPage(int start)
start
- the 1-based start pagejava.lang.IllegalArgumentException
- if the start page is smaller than one.public void setEndPage(int end)
end
- the 1-based end pagejava.lang.IllegalArgumentException
- if the end page is smaller than one.private void processPages() throws java.io.IOException
java.io.IOException
- If an IO error occurs.private void createNewDocumentIfNecessary() throws java.io.IOException
java.io.IOException
- If there is an error creating the new document.protected boolean splitAtPage(int pageNumber)
protected void splitAtPage()
{
// will split at pages with prime numbers only
return isPrime(pageNumber);
}
pageNumber
- the 0-based page number to be checked as splitting pageprotected PDDocument createNewDocument() throws java.io.IOException
java.io.IOException
- If there is an problem creating the new document.protected void processPage(PDPage page) throws java.io.IOException
page
- The page that is about to get processed.java.io.IOException
- If there is an error creating the new document.private void processAnnotations(PDPage imported) throws java.io.IOException
java.io.IOException
protected final PDDocument getSourceDocument()
protected final PDDocument getDestinationDocument()