PDFBox-查找页面尺寸 [英] PDFBox - find page dimensions
问题描述
如何使用PDFBox查找(以毫米为单位)pdf页面的宽度和高度?目前,我正在使用此:
How can I find(in mm) the width and the height of a pdf page using PDFBox? Currently, I'm using this:
System.out.println(page.getMediaBox().getHeight());
System.out.println(page.getMediaBox().getWidth());
但结果是(不是毫米):
but the result is(not in mm):
842.0
595.22
推荐答案
Measurement units inside a PDF are in points, a traditional graphic industry measurement unit. Adobe uses the following definition:
1 pt = 1/72 inch
由于1英寸的精确定义为25.4毫米(真的!),因此您可以使用公式将点从mm转换为mm
and since one inch is defined to be exactly 25.4 mm (really!), you can convert from points to mm using the formula
mm = pt*25.4 / 72
顺便说一句,您的值将(松散地)转换为A4纸张尺寸210 x 297毫米. (松散"的原因有两个:首先:A x 尺寸是从公制中的1平方米得出的.点是基于(根据Adobe的用法)英制;因此,所有点和毫米之间的转换是近似值;其次:A4的给定毫米值也要四舍五入A x 相对尺寸和绝对尺寸基于
Your values, by the way, translate (loosely) to the A4 paper dimensions 210 x 297 mm. ("Loosely", for 2 reasons. First: Ax dimensions are derived from 1 square meter, in the metric system. Points are based (according to Adobe's usage) in the imperial system; therefore, all conversions between points and millimeters are approximations. Second: the given value in mm for A4 is rounded as well. Ax relative and absolute sizes are based on an irrational number.)
在对象流中,可以将度量单位缩放为其他单位.以上仅适用于顶级基础对象.
Inside an object stream, units of measurement can be scaled to something else. The above is only true for top level base objects.
这篇关于PDFBox-查找页面尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!