8

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.

Community
  • 1
  • 1
Rakesh Shetty
  • 4,548
  • 7
  • 40
  • 79
  • 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. – Gourav Yadav Sep 01 '21 at 11:59

12 Answers12

16

use full directory path with .jpg image

Rameshkrishnan S
  • 413
  • 1
  • 3
  • 8
  • 1
    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. – Rameshkrishnan S Jun 01 '13 at 10:31
  • yeah thanks I converted my image to jpg and its working perfectly thanks :) – Rakesh Shetty Jun 01 '13 at 11:25
  • 1
    @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. – BrianS Jun 03 '13 at 17:13
  • 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 – richhallstoke Jun 12 '15 at 15:31
  • 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. – Gourav Yadav Sep 01 '21 at 11:58
4

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';?>"/>
manish1706
  • 1,571
  • 24
  • 22
2

Don't put full path of URL, just put foldername/filename.jpg

Example:

<img src="uploads/kuruvi.jpg">
Gerry
  • 10,337
  • 3
  • 31
  • 40
Shannu Sha
  • 31
  • 2
2

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" />
Naved Khan
  • 1,699
  • 16
  • 13
0

if I recall it correctly you can put there a full system path to that image - absolute or relative to your script

Ochi
  • 1,468
  • 12
  • 18
0
//use full directory path something like this    

    $currentsite = getcwd();
    $html = <<<HTML
    <html>
    <img src="{$currentsite}/sites/all/modules/certificate_handler/image002.png" alt="" /></a>

     </html>
    HTML;
Developer
  • 3,857
  • 4
  • 37
  • 47
0

Remove the alt attribute and changing it from a self-closing tag (/>) to a normal one (>). It worked for me.

Note: dompdf seems to have a bad response to any inline styles on img tags, so I suggest removing them if you´re using any.

Nic
  • 6,211
  • 10
  • 46
  • 69
0

I did this:

$imgurl       = $graficas[$i]; 
$path_parts   = pathinfo($imgurl);
$graficas[$i] = $path_parts['filename'].".jpg";

And works. I hope this would help you too

0

DOMPDF

working now with png,jpg.

here what I used.

I have index.php file in route folder and image in subfolder namely images.

$image ="images/".$_FILES['image_index_name']['name'];
$htm= '';
Antikhippe
  • 6,316
  • 2
  • 28
  • 43
-1

You just have to change the line def("DOMPDF_ENABLE_REMOTE", FALSE); to true in the file DOMPDF_CONFIG.INC

Szabolcs Páll
  • 1,402
  • 6
  • 25
  • 31
-1

Now latest DOMPDF version another, but have the same problem on PHP v5.3

Upgrade to v5.4 or higher

The problem has solved.

krolovolk
  • 464
  • 6
  • 18
-4

I think you could add this

private function change_url_image($data,$url){  
$str=$url; //for example "http://localhost/yoursite/";
$str2=str_replace($str,"",$data);
return $str2;
}

to change url for image it's very simple

  • 1
    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)`. – Nic Jun 04 '15 at 15:18