'dompdf and img tag, image wont show

Here is the HTML just before $dompdf->render() and $dompdf->output() are called:

<img src="http://www.example.com/images/Logo.png" />

All other invoices display the image fine when viewing in the browser, or printing it, or emailing it as HTML. When I click 'Generate PDF' inside of our application, it renders the invoice in PDF, except the logo is missing. I have put a debugging line in to email me the raw HTML it sends to the render(), and it looks fine to me.

Does anyone have any idea why dompdf won't display this image?



Solution 1:[1]

An idea: if you are providing full URI to the image it is treated as external, so defined costant DOMPDF_ENABLE_REMOTE must be set to true.

Solution 2:[2]

Looks like you have to pass the server path and not the server url in the src param

http://www.flashnutz.com/2009/08/images-not-working-in-dompdf/

Solution 3:[3]

My .png image would not load mysteriously but it would display when I outputted the html before rendering.

I was able to debug using this

global $_dompdf_show_warnings;
$_dompdf_show_warnings = true;      
\Dompdf\Image\Cache::clear(true);
$options = new \Dompdf\Options(['debugPng' => true,'isRemoteEnabled'=>true);
$dompdf->setOptions($options);

The output file was located at C:/Users/USERNAME/AppData/Local/Temp/log.htm

But the error showed there was a permissions error.

The true cause of my grief was a simple whitespace at the beginning of the src=""

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 dev-null-dweller
Solution 2 Sandeepan Nath
Solution 3 user24601