I have a small issue with mPDF (version 5.7.1).
This code should generate PDF with image file:
$mpdf = new mPDF();
$html = '<img src="https://www.google.pl/images/srpr/logo11w.png"/>';
$mpdf->WriteHTML($html);
$mpdf->debug = true;
$output = $mpdf->Output();
exit();
Well there is no image but an [x]
instead.
I've googled enough to get to the conclusion that it has to be done this way but I also tried realpath to the file. Still nothing.
The only thing I haven't tried is <img src="logo11w.png">
and copying the image into the folder because I don't know into which folder I should copy file logo11w.png
.
Any suggestions?
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:
Usualy people don't have installed GD module for PHP. On linux machine, execute:
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:
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.
change to remove the second line before initializing $html its undefined at that time. new code will be as
It's enough The solve is :
It's all
I have encountered the same problem after migrating the script.
The problem was, that the
tmp
directory inside the mpdf folder was not writable. I hope it helps someone.In my case, the problem was just the usage of transparents PNG using the 6.0 version. This bug was fixed on the mpdf 6.1 version.
I successfully solved the problem downloading the 6.1 version from here and overriding the mpdf files on my project.
Ok. After the last comment on question (14:30). Here the exact same code that IS working with mPDF 5.4. And it saves it's output on scripts directory as test.pdf. Firewall issues?
Edited
I have the following directories / files:
So these image files are relatively starting from the script directory as it looks like.
Fully working example (download)