Forum How do I...?

Images are being auto-sized in Prince 7.1

dwhalenenr
Hello.

I am using Prince to create a report. The report contains PNG charts. I create the images to be 600x400 pixels, but whenever I export to Prince for PDF creation the images are larger inside the PDF. Often as much as 10% larger. This leads to fuzzy/blurry images due to the size expansion.

I'm using Prince 7.1. How do I stop this from happening?

Thanks in advance,

DW
StoneCypher
Either set the size of the image, so that prince no longer has to fill the display block, or set the resolution of the image (or all images). I personally prefer the latter strategy, because it makes Prince do the right thing by default for all images.

There are a lot of ways to do it, but you probably want a CSS rule something like this:

* { prince-image-resolution: 300dpi; prince-background-image-resolution: 300dpi; }


And that just says the obvious common-sense desired thing: "for all images and background images, use 300 DPI unless I say otherwise."

John Haugeland is http://fullof.bs/

dwhalenenr
Thanks, John. I'll try that, although I had been explicitly setting the image size like so:

[img src="img.png" width="600" height="400" style="width:600px;height:400px;" border="0" /]

Which I was so surprised is wasn't working.

It's almost as if Prince is magnifying the whole document. Is that possibly my issue?

DW
StoneCypher
Sort of.

HTML units refer to pixels. As of HTML 4.01, pixels are a virtual grid. Prince respects the pixel as the pica, IIRC (I'm not actually sure about this,) in that each pixel becomes 1/72.27 inch. Or 1/72. Or whatever, I can never remember.

You can see this pretty clearly by setting a one pixel border around seriffed text, and observing how thick that pixel is with respect to the text.

There is a Prince property somewhere that sets the size of a pixel, but I retreated from pixel measurement for my printables because it's generally inherited from code intended for screens, and that code rarely makes choices that are good on paper.

John Haugeland is http://fullof.bs/

StoneCypher
You actually face a nearly identical problem trying to deploy HTML to the iPhone 4, and fighting the viewport scaling nonsense. Different set of properties, but it's the exact same conceptual issue.

John Haugeland is http://fullof.bs/

dwhalenenr
Very Interesting Stuff.

Well, when I apply the CSS you suggested I definitely see a change in the images. They render too
small, naturally, since I'm using screen resolutions and 300dpi is too high.

It does make me think though -- is the real solution to use different units? Inches perhaps? Or do I need to keep fiddling with DPI until I get a good fit?

Thanks again for the help!

DW
mikeday
Specifying a width/height in absolute units like mm or inches will give you a guaranteed size on the paper. Currently Prince assumes 96dpi for pixel units, so 96px = 1in.