dompdf and img tag, image wont show
Asked Answered
C

3

7

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?

Cirillo answered 1/12, 2010 at 18:50 Comment(2)
Which version of DOMPDF are you using? I can't remember the exact limitations, but I believe 0.5.1 had issues with alpha transparency in PNG. This was mentioned here: drupal.org/node/558170#comment-1981550Martimartial
WOW THANKS! Thats what it was. Ugh!Cirillo
T
16

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.

Tiein answered 1/12, 2010 at 20:18 Comment(1)
With the version 0.7 of DomPDF, constants are not used anymore. Use this instead : $dompdf = new Dompdf(array('enable_remote' => true));Squeegee
B
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/

Briefs answered 1/12, 2010 at 20:13 Comment(4)
Server path doesn't seem to work. Going to try again.. DOMPDF_ENABLE_REMOTE is also set to TRUE.Cirillo
Does it matter if the site is served out of /home/user/public_html?Cirillo
@Cirillo I worked long back that too on fpdf, and never worked on images with pdf generation. I just found this on searching. Is this not mentioned in the manual? I don't think /home/user/public_html would matter if the src param expects server path.Briefs
You should be able to use either a full URL or an absolute/relative path. Full URLs require a few conditions: 1) DOMPDF_ENABLE_REMOTE is true; 2) The web server has read/write access to the directory specified by DOMPDF_TEMP_DIR; 3) allow_url_fopen is true.Martimartial
G
0

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=""

Gram answered 19/4, 2022 at 16:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.