如何在 PDFBox 2.0 中创建 PageDrawer 实例? [英] How to create PageDrawer instance in PDFBox 2.0?

查看:83
本文介绍了如何在 PDFBox 2.0 中创建 PageDrawer 实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当有高边距时,我无法替换 PDF 文档中的 PDF 页面.如何使用 pdfbox2.0 调整 PDF 页面大小?

I could not replace PDF page in PDF document when there is high margin. How to resize PDF page using pdfbox2.0 ?

如果 pdf 页面内容(在输入 pdf 文档中)为 6" x 8" - 那么我想将页面大小设为 5" x 7" 并保存 pdf 文档

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

推荐答案

假设你有一个 PDPage 对象:

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);

然后保存您的文档.

如果您使用的是 1.8,则使用 findMediaBox() 而不是 getMediaBox().

If you're using 1.8, then use findMediaBox() instead of getMediaBox().

设置cropBox可能更有用,方法类似.我真的不能说,因为我没有你的文件,也不知道你想解决什么真正的问题.调整 PDRectangle 的所有 4 个元素(请参阅 javadoc)而不仅仅是宽度和高度也可能很有用.

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.

这篇关于如何在 PDFBox 2.0 中创建 PageDrawer 实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆