How to create PageDrawer instance in PDFBox 2.0?

。_饼干妹妹 提交于 2019-12-12 03:36:45

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/37292264/how-to-create-pagedrawer-instance-in-pdfbox-2-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!