i split generate new pdf concatenating individual pages, last page has split @ point (i.e. content above limit included , below excluded - care ones having upper left corner above line). possible using pdfbox?
one way achieve task, i.e. split page at point (i.e. content above limit included , below excluded) prepend clip path.
you can use method:
void clippage(pddocument document, pdpage page, boundingbox clipbox) throws ioexception { pdpagecontentstream pagecontentstream = new pdpagecontentstream(document, page, true, false); pagecontentstream.addrect(clipbox.getlowerleftx(), clipbox.getlowerlefty(), clipbox.getwidth(), clipbox.getheight()); pagecontentstream.clippath(pathiterator.wind_non_zero); pagecontentstream.close(); cosarray newcontents = new cosarray(); cosstreamarray contents = (cosstreamarray) page.getcontents().getstream(); newcontents.add(contents.get(contents.getstreamcount()-1)); (int = 0; < contents.getstreamcount()-1; i++) { newcontents.add(contents.get(i)); } page.setcontents(new pdstream(new cosstreamarray(newcontents))); }
to clip given page along given clipbox. (it first creates new content stream defining clip path , arranges stream first 1 of page.)
e.g. clip content of page along horizontal line 650 units above bottom, this:
pdpage page = ... pdrectangle cropbox = page.findcropbox(); clippage(document, page, new boundingbox( cropbox.getlowerleftx(), cropbox.getlowerlefty() + 650, cropbox.getupperrightx(), cropbox.getupperrighty()));
for running example here: clippage.java.
Comments
Post a Comment