准备好现有的 PDF 页面大小(例如 8.5 x 11、11 x 17)VB.Net

发布于 2024-10-10 15:44:42 字数 78 浏览 9 评论 0原文

就像标题所说,我想用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

机场等船 2024-10-17 15:44:42

给定页面可以有许多不同的“框”:

媒体框(必需):打印查看时的初始页面大小。
裁剪框(可选):取代媒体框。默认匹配媒体框。必须是媒体框的子集或匹配。

还有艺术/装饰/出血框,但它们并不那么重要,而且不太常见。

因此,页面大小:

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),但它仅适用于媒体盒,所以如果我是你,我会自己做。只需要几行额外的代码:

// rotation has to be 0, 90, 180, or 270.  "360" isn't kosher IIRC.
if (reader.getPageRotation(pageNum) % 180 != 0) {
  float tmp = width;
  width = height;
  height = tmp;
}

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 is getPageSizeWithRotation(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:

// rotation has to be 0, 90, 180, or 270.  "360" isn't kosher IIRC.
if (reader.getPageRotation(pageNum) % 180 != 0) {
  float tmp = width;
  width = height;
  height = tmp;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文