Search code examples
phpimagewkhtmltopdfcentos6

Wkhtmltopdf not rendering images


I'm trying to save a page from my site to pdf. I was able to get the style sheets to work using absolute URLs, but have not been able to get the images to render no matter what.

I have tried using relative urls, absolute urls - even the '/var/www/vhosts...' server path. No error is reported, and no image is rendered. The space where the image should be is collapsed as if it weren't even part of the code!

I've tried wkhtmltopdf versions: 11.0 RC1, 10.0 RC2 and 9.9. Running Cent OS 6.3.

I am using the php class PHP WkHtmlToPdf (http://mikehaertl.github.io/phpwkhtmltopdf/). I haven't tried to run the same command on the command line as the page that I'm rendering is password protected and uses Session variables.

The same page does render perfectly in the browser.

I've tried every solution I can find - any help would be greatly appreciated!


Solution

  • I stumbled across the answer accidentally today.

    My image is contained within an absolutely positioned div with a percentage based height and top position. On the website, the containing div has a defined height, so this works fine. On the print copy, this div is no longer present so it seems that it was either positioning the image-holding div off the page, or reducing it's height to 0. Either way - putting a full-page size absolutely positioned div around the elements not only made the image render correctly, but also corrected the positioning of the other absolutely positioned elements on the page!