Home > PHP > Images not working in dompdf

Images not working in dompdf

August 6th, 2009

What is dompdf?  Well basically its a HTML to PDF converter. It's rendering engine is built in PHP and is style-driven which means it will download and read external stylesheets, inline style tags, and the style attributes of individual HTML elements.

I won't go into detail of how to use it (unless you want me to or would like to write about it), but recently I  had an issue with images not rendering  in the pdf. At first I thought it was a permissions problem, then I thought it was an image type problem. It turns out it was a file location issue.

instead of the file location being:

<img src="images/myimage.jpg" style="width:200px;height:200px">

It should be:

<img src="/var/www/images/myimage.jpg" style="width:200px;height:200px">

So as you can see it needs to reference the file from the server side file directory and not just from within the web directory.

Wish someone wrote this, when I needed it....

Post to Twitter Post to Plurk Plurk This Post Post to Yahoo Buzz Buzz This Post Post to Delicious Delicious Post to Digg Digg This Post Post to Ping.fm Ping This Post Post to Reddit Reddit Post to StumbleUpon Stumble This Post

Flashnutz PHP , , ,

  1. Andrey
    September 1st, 2009 at 02:03 | #1

    Thank you so much for this! I was cracking my head about this issue, thinking it had something to do with the framework I use – symfony. But then I’ve seen your article and – bing – got it!
    The only addition though, in my case I have production and development enviroments on different servers, so I could’t hard-code absolute path. Insead I use php function getcwd() to get absolute path to current directory:

  2. September 1st, 2009 at 22:58 | #2

    No problem.. I was smashing my head against the wall on this one too.

    Glad it helped.

    Thank you for sharing how you fixed your issue.

  3. Kurtis
    November 9th, 2009 at 12:46 | #3

    this is a good one, I had that problem, and now it’s solved, but the include image is way too tiny, even though I put the with and size, I have to zoom at 400% just to see that the image is there, that’s not normal

  4. Unknown
    December 31st, 2009 at 19:01 | #4

    Thanks Guyz. Great help.

  5. Allan
    February 18th, 2010 at 10:20 | #5

    This was a great help to me as well. My web directory is set up differently, and it took a couple tries to get it work. Also, one thing that’s good to remember is DPI. PDF is a print file, and by default in the config file set to 150 DPI. Web DPI is 72. I had to increase all image dimensions by 48% in order to get them to the same dimensions.

  1. No trackbacks yet.
SEO Powered by Platinum SEO from Techblissonline