I'm using dompdf to generate a PDF file. In the file I'm including an image that is generated on the fly by PHP by using;
<img src="image.php" />
When I view the page I can see an error saying "Image not found" which links to the supposedly not found image which displays fine when you click on it.
I've tried adding a .png extension to the page generating the image but that doesn't make any difference. I've also saved the generated image to the server and linked to that instead and it works fine.
The only method I can think of to solve this is to save the image on the server and then link to that. Ideally, I don't want to do this so I was wondering if anybody had come across this before or if anyone can think of a fix for it.
The version of dompdf I'm using is 0.6.0 beta 3 and I'm using it with CodeIgniter.
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:
$dompdf->load_html_file('http://example.com/mydoc.html');
. When you do this the image reference will be interpreted ashttp://example.com/image.php
.<img src="http://example.com/image.php" />
.First add this tag
img src="image.php"
, you need to specify the complete root where is located your image, so it most end in the format required like JPG or PNG, etc., and in the configuration file (dompdf_config.inc.php
) you need to change this lineDOMPDF_ENABLE_REMOTE
, which his default value is false change it to true and that is all :)You can use as an alternative supported the Base64 image data
Get the image from php in base64: