Dompdf remote image is not displaying in pdf

后端 未结 17 2145
臣服心动
臣服心动 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 17:59

    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

    0 讨论(0)
  • 2020-12-09 17:59

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

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

    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?)

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

    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.

    0 讨论(0)
  • 2020-12-09 18:02
    $data = {{any html content with src & href links}}
    

    Sometimes it may happen based on the unsecure url like https with invalid ssl certificate. so the renderer of dompdf cannot be accessed the url for fetching the content. check your content has any unsecure url. If you're using that url with process as unsafe option in browser, please use the following method. It replace the url to abspath

    $url = "https://example.com";
    $abspath="/home/public_html/example" || getcwd();
    $data =  preg_replace('#(src=\"[\s\r\n]{0,})('.$url.')#','$1'.$abspath, $data);
    $data =  preg_replace('#(href=\"[\s\r\n]{0,})('.$url.')#','$1'.$abspath, $data);
    
    0 讨论(0)
  • 2020-12-09 18:02

    Go to library/dompdf/scr/option

    change private $isRemoteEnabled = false; to private $isRemoteEnabled = true;

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