2
Inches = Pixels / dpi

I noticed that PDF Clown uses measurements in float: how do I convert inches and pixels to float for width, height, etc. to properly work in PDF? Does anybody have a mathematical formula for this?

1) Inches --> float

2) Pixels --> float
fletchsod
  • 3,560
  • 7
  • 39
  • 65
  • 1
    *PDFClown, it use measurement in float* - Which operations are you talking about? If you have low level methods on your mind, please be aware that in PDF content streams the coordinate system ( and, thus, the units of measurement) may constantly change. – mkl Apr 07 '15 at 22:41

1 Answers1

3

PDF's coordinate system is based on the concept of device independence, that is the ability to preserve the geometric relationship between graphics objects and their page, no matter the device they are rendered through. Such device-independent coordinate system is called user space. By default, the length of its unit (approximately) corresponds to a typographic point (1/72 inch), defining the so-called default user space.

But, as mkl appropriately warned you, the relation between user space and device space can be altered through the current transformation matrix (CTM): this practically means that the user space unit's length matches the typographic point only until skewing or scaling are applied! Furthermore, since PDF 1.6 default user space unit may be overridden setting the UserUnit entry in the page dictionary.

So, the short answer is that, in PDF, one inch corresponds to 72 default user space units (no CTM interference granted); on the other hand, as this coordinate system is (by-definition) device-independent, it doesn't make sense to reason about pixels -- they exist in discrete spaces of samples only, whilst PDF defines a continuous space of vector graphics which is agnostic about device resolution! See the following picture:

enter image description here

If you need to map into PDF some graphics which are natively expressed in pixels, then prior conversion to inches may be a sensible approach.

BTW, floating-point data type was chosen to represent user space measurements just because it was obviously the most convenient approximation to map such a continuum -- I guess that after this explanation you won't confuse measures with measurements any more.

An extensive description about PDF's coordinate system can be found in § 4.2 of the current spec.

  • Ok. Instead of pixels, what I have is width in 1.3124 inches. To convert inches to points, using the 1/72 as 72 points in 1 inch, would be this --> points = (inches / 1.0f) * 72f . Right? – fletchsod Apr 08 '15 at 17:44
  • 1
    @fletchsod Why so unnecessarily convoluted? points = inches * 72 – Stefano Chizzolini Apr 08 '15 at 20:08
  • I came from ActiveReports background that doesn't use points but inches and we have customers being instructed to use inches when uploading images to the cloud website which the ActiveReports script then read from. We're talking about over 30 different PDF templates. I'm still learning how to do it low level since ActiveReports automatically do the dirty work internally. With ActiveReports, x & y axis coordination was done in inches too. So, I'm still learning to think low level cuz ActiveReports doesn't allow me to think that way. Thanks. – fletchsod Apr 08 '15 at 20:36
  • 1
    You are welcome. I hope my explanation may be useful. – Stefano Chizzolini Apr 08 '15 at 20:45
  • They are as I'm doing the measurement conversion, so customer stuff dont get messed up. :-) – fletchsod Apr 08 '15 at 21:00