mPDF 5.7.1 - image displays as a broken [x]

后端 未结 11 1287
没有蜡笔的小新
没有蜡笔的小新 2020-12-29 05:59

I have a small issue with mPDF (version 5.7.1).

This code should generate PDF with image file:

 $mpdf = new mPDF();
 $html = \'

        
11条回答
  •  忘掉有多难
    2020-12-29 06:26

    Including images is kinda tricky in mPDF. I had some issues as well. I found more kind of problems.

    At first you should turn on debug variable:

    $mpdf = new mPDF();    
    $mpdf->showImageErrors = true;
    

    Usualy people don't have installed GD module for PHP. On linux machine, execute:

    sudo apt-get install php5-gd
    sudo service apache2 restart
    

    On Windows servers, php_gd2.dll is included in a standard PHP installation, but is not enabled by default. To enable it, uncomment the extension=php_gd2.dll line in your php.ini file (remove the # from the beginning of that line) and restart the PHP extension. [1]

    If you get this error you probably see [x] image:

    mPDF error: IMAGE Error (http://www.domain.com/directory/image.jpg): Could not find image file

    Check the url if your image exists and if the image is accessible. If yes then you can try to change absolute URL to relative. You can try both versions:

    
    
    

    Actually I also had a problem with PNG formats. Converted PNG image to JPG worked fine.

    Linking in mPDF templates should be same like for whole your framework/system.

提交回复
热议问题