Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding an image with dompdf

Tags:

php

dompdf

I'm building a PDF with dompdf, but my pdf doesn't contains a specified image. I already set the value to true in dompdf_config.inc.php

def("DOMPDF_ENABLE_REMOTE", true);

and this is my image HTML item:

<img src="logoweb.png" width="150" height="150"/>

What is happening? How can I show the image within my PDF?

like image 338
zeta_reticuli Avatar asked Aug 23 '26 12:08

zeta_reticuli


1 Answers

You should convert your image to base64 encoding for pdf.

<?php
$path = 'logoweb.png';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
?>
<img src="<?php echo $base64?>" width="150" height="150"/>
like image 116
Bishwa Timilsina Avatar answered Aug 25 '26 01:08

Bishwa Timilsina



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!