Image is not shown in PDF file using dompdf
Solution 1
use full directory path with .jpg image
Solution 2
It works 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';?>"/>
Solution 3
Don't put full path of URL, just put foldername/filename.jpg
Example:
<img src="uploads/kuruvi.jpg">
Solution 4
I my case i spend 2 hour finally i got answer img src not working with url or path you should covert it base64 format
<?php
$data = file_get_contents('https://teafloor.com/wp-content/themes/teafloor2-0/assets/images/logo.png');
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
?>
<?php echo '<div class="company-logo">
<img src="'.$base64.'" alt="base" />
</div>';
?>
or
<img src="<?php echo $base64; ?>" alt="base" />
Rakesh Shetty
Software engineer with a experience of 5 years in web development.Having an extreme passion to work on Front End technologies as well as on the Server Side. Specialist on : PHP,jQuery, Javascript, Ajax.Codeigniter and other frameworks. HTML, HTML5,CSS MYSQL, PostgreSQL, Oracle and other open source database. Social Media Application (Facebook,Twitter,Google Plus and others). API for Android, IOS.
Updated on July 09, 2022Comments
-
Rakesh Shetty almost 2 years
I am using DOMPDF to convert the html into PDF and after converting I'm sending that PDF file to user mail id.
Everything is working perfectly but in PDF file I am not able to see the image of logo of my site. I also searched in stackoverflow for previous question such as :- error in pdf image using dompdf , dompdf and img tag, image wont show
I also set
DOMPDF_ENABLE_REMOTE
toTRUE
andDOMPDF_PDF_BACKEND
toCPDF
my image tag is :-
<img src="http://www.example.com/clients/myprojects/images/logo.png" alt="" /></a>
I'm giving full path of my website but still it does not show image in my PDF file.
Thanks in advance.
-
Rakesh Shetty about 11 yearsthank for your reply but absoloute or realtive path doesn't work
-
Ochi about 11 yearswhat is your setup? is dompdf on the same server as images you are trying to include?
-
Rameshkrishnan S about 11 yearsa year back I tried png was not working. so I did with jpg image. not sure current status of the dompdf compatability with png.
-
Rakesh Shetty about 11 yearsyeah thanks I converted my image to jpg and its working perfectly thanks :)
-
BrianS almost 11 years@RakeshShetty FYI, dompdf has to do some pre-processing of PNG images to handle transparency. You'll want to make sure GD support is enabled in PHP.
-
Nic almost 9 yearsVery simple answer. Also a very useless one, since you don't explain how to use it. Plus, the whole thing could be simplified to just one line of code, which eliminates the utterly redundant
$str
and equally badly named$str2
:return str_replace($url, "", $data)
. -
Developer almost 9 yearssorry about that. while highlighting as code I missed that line. fixed now :)
-
richhallstoke almost 9 yearsI can also confirm PNG images do not work properly in v0.5.0, use JPG instead and then there's no problems! Thank you @Rameshkrishnan_S
-
Yevgeniy Afanasyev about 5 yearsThis is the best. I could not grasp that "full path" means "local path" until I see this answer. Thank you.
-
Gourav Yadav almost 3 yearsif you are still getting the issue in image, then you can debug the issue on this file: vendor/dompdf/dompdf/src/Image/Cache.php you will get the understanding from where the issue is occuring.