PDFBox - find page dimensions

筅森魡賤 提交于 2019-11-30 10:56:48
usr2564301

Measurement units inside a PDF are in points, a traditional graphic industry measurement unit. Adobe uses the following definition:

1 pt = 1/72 inch

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

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

Footnote

Inside an object stream, units of measurement can be scaled to something else. The above is only true for top level base objects.

Coordinates in DTP points are defined as: 1 pt = 1/72 inch = 25.4/72 mm

You could write a method like this:

public float pt2mm(float pt) {
   return pt * 25.4f / 72;
}

If the document is created using a different DPI than 72 then use the more general formula:

public float pt2mmForWeb72dpi(float pt) {
   return pt2mm(pt,72);
}
public float pt2mmForPrint300dpi(float pt) {
   return pt2mm(pt,300);
}
public float pt2mmForPrint600dpi(float pt) {
   return pt2mm(pt,600);
}
public float pt2mm(float pt, float dpi) {
   return pt * 25.4f / dpi;
}

You can find more at https://forums.indigorose.com/forum/indigo-rose-software/developer-s-den/13282-what-is-the-size-of-a4-in-px

A4 is a document format, as a screen image that's going to depend on the image resolution, for example an A4 document resized to:

  • 72 dpi (web) = 595 X 842 pixels
  • 300 dpi (print) = 2480 X 3508 pixels (This is "A4" as I know it, i.e. "210mm X 297mm @ 300 dpi")
  • 600 dpi (print) = 4960 X 7016 pixels

And so forth. FWIW document formats like A4 are described by their print dimensions (millimeters), which is a whole different thing than screen images (pixels) so that's why you don't see anyone using pixels to describe A4. :yes

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