准备好现有的 PDF 页面大小(例如 8.5 x 11、11 x 17)VB.Net
就像标题所说,我想用 VB.Net 读取现有的 pdf 页面大小。我一直在使用 Itext.Sharp 和 Acrobat.dll。这可能吗?
Like the title says i'd like to read an existing pdf page size with VB.Net. I've been working with Itext.Sharp, and the Acrobat.dll. Is this possible??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
给定页面可以有许多不同的“框”:
媒体框(必需):打印查看时的初始页面大小。
裁剪框(可选):取代媒体框。默认匹配媒体框。必须是媒体框的子集或匹配。
还有艺术/装饰/出血框,但它们并不那么重要,而且不太常见。
因此,页面大小:
PdfReader reader = new PdfReader(myPath);
// 获取媒体盒
矩形 pageRect = reader.getPageSize(1); // 1 ->;第一页
// 如果存在则获取裁剪框,如果不存在则获取媒体框。
矩形cropRect = reader.getCropBox(1);
// 最后
矩形 artBox = reader.getBoxSize( 1, "art");
// 可以是“art”、“bleed”、“crop”、“media”或“trim”,
我会使用
getCropBox()
。我还建议您查看 JavaDoc 以了解此类内容。至少您会自己想出
getPageSize()
。不,这不是 C#。是的,它非常有用。http://api.itextpdf.com/
另请注意,这些矩形不需要基于 0,0 (这将是未旋转页面的左下角)。
此外,您应该检查页面的旋转,
getPageRotation(int)
,如果旋转为 90 或 270,则交换高度和宽度。有getPageSizeWithRotation(int)
,但它仅适用于媒体盒,所以如果我是你,我会自己做。只需要几行额外的代码:There are a number of different "Boxes" a given page can have:
Media Box (required): The initial page size when printing viewing.
Crop Box (optional): Supersedes the media box. Defaults to match the media box. Must be a subset or match the media box.
There's also art/trim/bleed boxes, but they don't matter as much and are much less common.
So, the page size:
PdfReader reader = new PdfReader(myPath);
// gets the MEDIA BOX
Rectangle pageRect = reader.getPageSize(1); // 1 -> first page
// gets the crop box if present, or the media box if not.
Rectangle cropRect = reader.getCropBox(1);
// and finally
Rectangle artBox = reader.getBoxSize( 1, "art");
// could be "art", "bleed", "crop", "media", or "trim"
I'd go with
getCropBox()
.I also recommend checking out the JavaDoc for things like this. At the very least you would have come up with
getPageSize()
on your own. No, it's not C#. Yes, it's very useful.http://api.itextpdf.com/
Also note that these Rectangles need not be based on 0,0 (which would be the lower left corner on an unrotated page).
Further, you should check the page's rotation,
getPageRotation(int)
, and swap height and width if the rotation is 90 or 270. There isgetPageSizeWithRotation(int)
, but it only works with the media box, so I'd do it yourself if I were you. It's only a few extra lines of code: