Using 1.8.9
I want to cut a PDF page to a multi-page PDF using crop tools. But when I add more than one page to my PDDocument it doesn't add it at all.
Code example (the original PDPage is a parameter of my function) :
private static void splitPage(int nbOfCrops, PDPage myPage) throws IOException{
PDDocument pdfSplit = new PDDocument();
ArrayList<PDPage> pages = new ArrayList<PDPage>();
float croppingHeight = (myPage.findCropBox().getUpperRightY()/nbOfCrops);
for(int page = 0; page<nbOfCrops; page++){
pages.add(myPage); //Creates multiple copies of myPage
}
int splits = 0;
for(PDPage page: pages){
PDRectangle cropBox = page.findCropBox();
PDRectangle rectangle = new PDRectangle();
rectangle.setUpperRightY((float) (cropBox.getUpperRightY() - (croppingHeight* (splits))));
rectangle.setLowerLeftY((float) (cropBox.getUpperRightY() - (croppingHeight*(splits+ 1))));
rectangle.setUpperRightX(cropBox.getUpperRightX());
rectangle.setLowerLeftX(cropBox.getLowerLeftX());
page.setCropBox(rectangle);
pdfSplit.addPage(page);
splits++;
}
try {
pdfSplit.save("test.pdf");
System.out.println(pdfSplit.getNumberOfPages()); //Always returns 1
pdfSplit.close();
} catch (Exception e) {
e.printStackTrace();
}
}
So, what should I do/modify to add correctly each cropped pages ?
My document (if you want to see what I want to do) :
http://www.cinemas-utopia.org/admin/grilles/toulouse/2015-06-02.pdf