I could not replace PDF page in PDF document when there is high margin. How to resize PDF page using pdfbox2.0 ?
If pdf page content (in input pdf document) is 6" x 8" - then i want to make page size as 5" x 7" and save the pdf document
I could not replace PDF page in PDF document when there is high margin. How to resize PDF page using pdfbox2.0 ?
If pdf page content (in input pdf document) is 6" x 8" - then i want to make page size as 5" x 7" and save the pdf document
Assuming you have a PDPage
object:
PDRectangle mediaBox = page.getMediaBox();
if (mediaBox.getWidth() == 6 * 72 && mediaBox.getHeight() == 8 * 72)
mediaBox = new PDRectangle(5 * 72, 7 * 72);
and then save your document.
If you're using 1.8, then use findMediaBox()
instead of getMediaBox()
.
It might be more useful to set the cropBox instead, the methods are similar. I can't really tell because I don't have your files and don't know what real problem you're trying to solve. It might also be useful to adjust all 4 elements of the PDRectangle (see javadoc) instead of just the width and height.