Forum How do I...?

Images display differently in Prince 8

jhoweaa
I have a report that I've been generating using Prince 7 which uses 300 DPI images for a header graphic and some images in the report. The PDF produced by version 7 sizes the images correctly. I just installed Prince 8 on my development box to check out the latest version and when I run my report my images are extremely large. The images are being displayed as background images, not in img tags.

Did something change in the way Prince 8 handles image sizing? Is there something I need to specify now that I didn't need to specify before?

Thanks.
jbzech
I've been using 7.1 for a while now. When I took 8 for a quick spin, I noticed the same thing with images--they were suddenly huge. I didn't have time then to look into it. I'd be interested also in finding out what causes this difference before I consider upgrading.
mikeday
Prince 8.0 treats images more consistently with browsers. You can return to the old behaviour by applying this CSS:
img { prince-image-resolution: auto }

This will retrieve the DPI value stored in the image and scale the image based on that. You can also specify a specific DPI value, eg. 300dpi.
jhoweaa
The images I'm using are used as background images so I tried using the following:

* {prince-background-image-resolution: auto; prince-image-resolution: auto;}

and the images still came out large.

I'm also a little confused on the parameters to this option. The documentation says:

dpi | auto | normal [, normal | dpi]

what is 'normal' vs 'dpi'?

Thanks!
mikeday
You can use a fixed DPI value, eg. 300dpi, 600dpi, and so on. If you specify auto, that means to try and use the intrinsic DPI value specified inside the image file, if there is one. If you specify normal, that means to use 96dpi, so that an image 100 pixels wide will be exactly equivalent to specifying "width: 100px" in the CSS.
jhoweaa
I've tried a variety of definitions for the prince-background-image-resolution and my image always appears the same size, too large. The image itself is a PNG that was base64 encoded so we could inline the graphic rather than getting the file from a server, I don't know if that has any effect on this. All I know is that the image displayed perfectly in Prince 7 but doesn't display correctly in Prince 8 even with adding the prince-background-image-resolution property. We don't have an urgent need to move to Prince 8, but it would be nice to figure out why this isn't working, however.
mikeday
Another difference between the versions is that in Prince 7.1 we applied "img { max-width: 100% }" in the default HTML style sheets. We dropped this rule in Prince 8.0 as it was causing incompatibilities with browser behaviour, but you can still apply it yourself in your own style sheets.
jhoweaa
In playing around with a couple of different reports we are generating using Prince, I have been able to get the images in the report itself to look correct, but I can not get the header image to work correctly. In my CSS, I have the following:

@media print {
* {
prince-background-image-resolution: auto;
prince-image-resolution: auto;
}
img {
max-width: 100%;
}
}

later, I have this:

@page {
size: US-Letter;
margin: 1.2in .7in 1.2in .7in;
background: url(data:image/jpeg;base64 .... inline data ...) center .1in no-repeat;
@top {
margin-top: 20pt;
content: flow(header)
}
}

@media print {
.header {
flow: static(header);
position: relative;
height: 1.5in;
margin: 0;
}
}

In my HTML, I have something like this:

<body>
<div class="wrapper">
<div class="...">
<div class="header">
... some text
</div>
...


In Prince 7, the header graphic appears behind the text of the div with the class of 'header' and displays at about an inch tall. In Prince 8, the header graphic is roughly 3 times as tall. In Photoshop, the image details for the header image are 8.267 in x 0.917 in @ 300DPI.

Thanks.
mikeday
Try applying "@page { prince-background-image-resolution: auto }", as the * selector will only match elements, not @page rules.
jhoweaa
Applying the prince-background-image-resolution property to the @page item worked.

Thanks!