DomPDF: Image not readable or empty

后端 未结 9 1218
梦如初夏
梦如初夏 2020-12-15 16:41

For some reason, DomPDF won\'t render an image included in the html that is being parsed:

\"PDF

相关标签:
9条回答
  • 2020-12-15 17:36

    As there was another answer that suggests enabling the remote option in module.config.php and I can't yet add comments, I thought it would be best to answer that this file does not exist in newer versions of DomPDF.

    If you need to include remotely stored images in a newer version you have to pass it as an option to the constructor:

    $dompdf = new Dompdf(array('enable_remote' => true));
    

    This fixed the issue I had.

    0 讨论(0)
  • 2020-12-15 17:41

    Following helped me like charm, at least localy, and even with

    def("DOMPDF_ENABLE_REMOTE", false);
    

    The solution is to change the image SRC to the absolute path on the server, like this:

    <img src="/var/www/domain/images/myimage.jpg" />
    

    All of the following worked 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';?>"/>
    

    $_SERVER["DOCUMENT_ROOT"] is C:/wamp/www/ZendSkeletonApplication/public

    Thanks to this: lost in code

    0 讨论(0)
  • 2020-12-15 17:44

    Now (May 2018) the correct way is :

    $options = new Options();
    $options->set('isRemoteEnabled',true);      
    $dompdf = new Dompdf( $options );
    
    0 讨论(0)
提交回复
热议问题