Dompdf remote image is not displaying in pdf

后端 未结 17 2146
臣服心动
臣服心动 2020-12-09 17:28

On my server pdf generated via dompdf was not displaying images. Because they are remote url images.(local images are working fine) then I come to know that it needs some se

相关标签:
17条回答
  • 2020-12-09 18:05

    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.

    0 讨论(0)
  • 2020-12-09 18:05

    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>

    0 讨论(0)
  • 2020-12-09 18:07

    Try

    $options = new Options();
    $options->set('isRemoteEnabled', true);
    $dompdf = new Dompdf($options);
    
    0 讨论(0)
  • 2020-12-09 18:07

    Hi my solution to this problem was adding the enabling the allow_url_fopen in my php.ini file

    0 讨论(0)
  • 2020-12-09 18:11

    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.

    0 讨论(0)
  • 2020-12-09 18:11

    I had the same issue with images, and my solution was:

    getcwd().'path/to/image'
    

    It works for me!

    0 讨论(0)
提交回复
热议问题