Hey all,
We are using PDFBox 1.1.0. I am trying to use the
org.apache.pdfbox.util.Splitter class to split a document into two
documents, given a page# to split at. So I extended the Splitter class
and overriden the createNewDocumentIfNecessary as follows. However,
when I call the split method, the createNewDocumentIfNecessary is
executed once and a NullPointerException is thrown.
Please advise!
Thanks for your time!
Regards,
Joe
/* Here's the code */
PDFSplitter pdfSplitter = new PDFSplitter();
pdfSplitter.setNumPages(pdDocument.getNumberOfPages()); // The
document has 14 pages
pdfSplitter.setSplitAfterPageNum(4); // Split it into two documents
with first document containing 4 pages and the second one containing
10 pages.
List documents = pdfSplitter.split(pdDocument);
import java.io.IOException;
import org.apache.pdfbox.util.Splitter;
public class PDFSplitter extends Splitter {
private int numPages;
private int splitAfterPageNum;
// Constructors
public PDFSplitter() { super(); }
// Setter methods
public void setSplitAfterPageNum(int splitAfterPageNum) {
this.splitAfterPageNum = splitAfterPageNum;
}
public void setNumPages(int numPages) {
this.numPages = numPages;
}
// Override createNewDocumentIfNecessary method
protected void createNewDocumentIfNecessary() throws IOException {
System.out.println("Current Page#: " + this.pageNumber + " -
Split
After:" + this.splitAfterPageNum);
if((this.pageNumber + 1) == this.splitAfterPageNum ||
(this.pageNumber + 1) == this.numPages) {
System.out.println("Splitting here!");
super.createNewDocumentIfNecessary();
}
}
}