Dompdf remote image is not displaying in pdf

后端 未结 17 2144
臣服心动
臣服心动 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: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);
    

提交回复
热议问题