Dompdf remote image is not displaying in pdf

℡╲_俬逩灬. 提交于 2019-11-30 12:44:26

I had the same problem, dompdf image not found on live server

I found its solution, you just need to double check the image path,

Considering your live server image path

<img src="http://www.example.com/public/images/thumb.png">

You just need to change it to,

<img src="public/images/thumb.png">

Note: Make sure that, all settings are same as you have already made.

I hope this will help you.

Try

$options = new Options();
$options->set('isRemoteEnabled', true);
$dompdf = new Dompdf($options);
daudichya

There are two things to take care of.

  1. If using image from same server then use full directory path e.g. /var/www/html/project_folder/images/logo.jpg

  2. List item Use JPEG image instead of png or other types.

user2649610

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

Can you reach those URLs in your web browser on the machine that you're using to open the PDF? If not, the PDF reader won't be able to either.

I suspect that the "localhost" domain means that those URLs are only visible from the web server that generated the PDF. You need to output a url like http://example.com/dompdf/image.jpg

(To step around this issue, bear in mind that there are good reasons not to use remote images. The document will look bad if the viewer is not connected to the internet, for example. Is it possible to just embed the images directly in the document?)

dompdf doesn't currently have a mechanism for distinguishing between a local and remote domain, so any URL that starts http://... is treated as remote. Plus, any image that uses a PHP-based intermediary (like pic.php) can't use a local path because the PHP will not be parsed unless you go through a web server.

It's a difficult prospect, but your pages are generated dynamically. So I see two options:

  1. downloading remote images and linking to them on the local file system
  2. downloading remote images and using a data URI.

Since you've already worked out getting the image using curl you should be able to implement either one of these.

Same problem i was facing while i was also set the "DOMPDF_ENABLE_REMOTE=>true" in "dompdf/dompdf_config.inc" but not worked.

One thing worked for me change the src for images/css from absolute to relative and things done.in this case i have all the css/images on my server.

Just in case anyone has the same issues as me:

  • I changed src="https://" to src="http://" and the images loaded fine.

  • I also added all CSS inline within a <style> instead of loading via <link>

  • and make sure the CSS <style> is in the <head> not the <body>

I used this line of code

<img src="{{ url('/frontened/images/jeevan-green-logo.png') }}" >

It's working fine. Thanks.

I am giving you an example with function

  $html = $this->output->get_output();
        $this->load->library('pdf');
        $this->dompdf->loadHtml($html);
        $this->dompdf->set_option('isRemoteEnabled', true);
        $this->dompdf->setPaper('A4', 'portrait');
        $this->dompdf->render();
        $this->dompdf->stream("studentidcard.pdf", array("Attachment"=>0));

Set isremoteenabled true to show remote images

Go to the dompdf_config.inc.php file and set the variable DOMPDF_ENABLE_REMOTE to TRUE ...

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!