Question Detail

dompdf not showing image in pdf generated by PHP file

5 years ago Views 7529 Visit Post Reply

I am using DomPDF for creating PDF from HTML.
it is working but image not showing there. in pdf,  Images replace by cross Icon.
How can I resolve it?

Thread Reply


- 5 years ago

How are you loading your HTML document into dompdf? $dompdf->load_html()$dompdf->load_html_file()? To access a PHP-generated image you should be using the latter. Additionally, unless you are loading the document through a web server dompdf will grab the file itself, not the rendered file. Since image.php is not a valid image type dompdf will fail to load it.

There are two solutions:

  1. Load your document through your web server, e.g. $dompdf->load_html_file('');. When you do this the image reference will be interpreted as
  2. Reference your image using a full URL (including domain) so that your server processes it before sending it back to dompdf, e.g. <img src="" />.

Bili Greed

- 5 years ago

Following helped me like charm, at least localy, and even with


The solution is to change the image SRC to the absolute path on the server, like this:

<img src="/var/www/domain/images/myimage.jpg" />

All of the following worked for me:

<img src="<?php echo $_SERVER["DOCUMENT_ROOT"].'/placeholder.jpg';?>"/>
<img src="<?php echo $_SERVER["DOCUMENT_ROOT"].'\placeholder.jpg';?>"/>
<img src="<?php echo $_SERVER["DOCUMENT_ROOT"].'./placeholder.jpg';?>"/>

$_SERVER["DOCUMENT_ROOT"] is C:/wamp/www/ZendSkeletonApplication/public