3

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!

Alan
  • 389
  • 1
  • 7
  • 16

2 Answers2

6

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!

Alan
  • 389
  • 1
  • 7
  • 16
2

Here's one other reason your images may not be showing up on the PDF, despite rendering okay in the HTML.

If you have RewriteEngine on in a .htaccess file acting in the image's (or it's parent's) directory, it may be the reason.

To check this, comment out the rewrite conditions and try again.

To arrive at this point, I found out that curling the image on the command line helped throw some light on the problem. A command such as:

 curl "http://localhost/directory/path/logo.png"

might return Forbidden, with a message such as "You don't have permission to access ... on this server"

Ifedi Okonkwo
  • 3,406
  • 4
  • 33
  • 45