Image is not shown in PDF file using dompdf

32,573

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" />
Share:
32,573
Rakesh Shetty
Author by

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, 2022

Comments

  • Rakesh Shetty
    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 to TRUE and DOMPDF_PDF_BACKEND to CPDF

    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
    Rakesh Shetty about 11 years
    thank for your reply but absoloute or realtive path doesn't work
  • Ochi
    Ochi about 11 years
    what is your setup? is dompdf on the same server as images you are trying to include?
  • Rameshkrishnan S
    Rameshkrishnan S about 11 years
    a 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
    Rakesh Shetty about 11 years
    yeah thanks I converted my image to jpg and its working perfectly thanks :)
  • BrianS
    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
    Nic almost 9 years
    Very 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
    Developer almost 9 years
    sorry about that. while highlighting as code I missed that line. fixed now :)
  • richhallstoke
    richhallstoke almost 9 years
    I 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
    Yevgeniy Afanasyev about 5 years
    This is the best. I could not grasp that "full path" means "local path" until I see this answer. Thank you.
  • Gourav Yadav
    Gourav Yadav almost 3 years
    if 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.