views:

35

answers:

2

I am generating a PDF from HTML using a library, and all the size parameters that I am giving are in pixels. This seems kind of odd. I just googled the internet for A4 size in pixels, and can I just use these values everywhere?

Is this how it should be done? Will the generated PDF look correctly?

Otherwise, do I need to somehow compute the pixel size using information from the screen?

Then, how do PDF's work if they can be sent to others and still look comparatively the same?

A: 

PDF's inherently a print medium, and its internal coordinates work in terms of 'points' (72pts per inch). The PDF rendering software (Acrobat, FoxIt, Ghostscript, etc...) will query the output device for its DPI rating and internally convert all the point-basec coordinates into device-specific pixel sizes when it comes time to render the PDF for display/print.

You can specify sizes in pixels while building a PDF, certainly. But remember that pixel sizes differ. A 300x300 pixel image will be 1" x 1" square on a 300dpi printer, but 3" by 3" on a 100 dpi monitor.

Marc B
+2  A: 

PDF internally uses the same graphics model as PostScript. PDF is derived from PostScript. Basically,...

  • ...it uses the very same operators that are available in PostScript, but renames them from being long and fully readable to short 1-, 2- or 3-letter abbreviations;
  • ...however, it strips all features that make PostScript a full-blown programming language;
  • ...and it adds a few new graphics capabilities, such as tranparencies and direct TrueType fonts embedding.

PDF also uses the same basic measurement unit as PostScript: 72 points == 1 inch. You may also use fractions of points. This is the device independent way of stating dimensions.

If you ever use pixels, you can do so. If you do, the absolute size of a graphic object on the display or the printed paper then depends on the current resolution of the display or printer. A square of 72pt x 72pt is 1inch x 1inch at a 72dpi resolution. But it is 0.1inch x 0.1inch at a 720dpi resolution. Therefore using pixels is a device dependent way of stating dimensions.

A4 dimensions are *'width x height = 595 x 842 pt'.

+1: well summarized, even for the Joe Does of PDLs :-)
pipitas