Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mPDF 5.7.1 - image displays as a broken [x]

Tags:

html

php

image

mpdf

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?

like image 263
Mr.TK Avatar asked Feb 28 '14 10:02

Mr.TK


1 Answers

I had the same problem with PNG images being displayed as [X] when to generate PDFs with mPDF.

I added: $mpdf->showImageErrors = true;

After: $mpdf = new Mpdf();

and got the error message:

GD library required for PNG image (alpha channel)#

So after running apt-get install php5-gd generating a PDF with a PNG worked like a charm!

like image 94
ddn Avatar answered Sep 19 '22 15:09

ddn