Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mPDF not rendering images (mPDF error: IMAGE Error Could not find image file)

Tags:

php

mpdf

We are getting plagued with this which started in April on working server. Everything was fine with our application until the customer reported that PDFs were no longer displaying the images.

Our PDF is generated via a HTML render first. When the HTML render is displayed the Image shows correctly. Also the image shows correctly if the image URL as noted in the mPDF is copied and pasted into a new tab.

However... If we load the image from a DIFFERENT DOMAIN then the image is rendered correctly. loading the image via absolute path, relative path or URL path all result in this error:

mPDF error: IMAGE Error (http://www.aibsonline.co.uk/logo.gif): Could not find image file

But, as you will see the logo url works when pasted. File permissions have been tested (which is why it is in the root) as standard and up to 777. Server is a Linux server in both cases we have seen so far.

HTML Code that renders the logo:

<div id="logo_wrapper" class="left">
<img width="107" height="76" src="<?php echo base_url('logo.gif'); ?>" />
</div>

At a real loss with this one and it is beginning to affect more and more clients.

Any help gratefully received.

UPDATE

The image renders if the rendering code and the image are in the same directory and we do NOT use an absolute path, eg.

<img width="107" height="76" src="logo.gif" />
like image 903
alcomcomputing Avatar asked May 07 '14 09:05

alcomcomputing


People also ask

What is Mpdf file?

mPDF is a PHP library which generates PDF files from UTF-8 encoded HTML. It is based on FPDF and HTML2FPDF (see CREDITS), with a number of enhancements. mPDF was written by Ian Back and is released under the GNU GPL v2 licence.

How do I change page size in Mpdf?

When declaring an instance of \Mpdf\Mpdf class, you can specify the (default) page size and orientation for the document. The margins and orientation can be redefined throughout the document whenever you add a new page using AddPage() or <pagebreak>. It can also be set by CSS using @page.


2 Answers

I had a similar issue and I solve by following:

1.Check if gd library is installed and enable in your php ini file. If not install gd library.

2.Turn on debug variable

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

3.Try inter-changing absolute/relative path for the image

<img src="http://someDomain/directory/image.jpg">
<img src="./directory/image.jpg">

Hope this helps.

like image 66
Gyan Avatar answered Oct 10 '22 07:10

Gyan


I tried all other answers here but for me, only adding

$mpdf->curlAllowUnsafeSslRequests = true;

fixed the issue.

like image 45
zanvidmar Avatar answered Oct 10 '22 07:10

zanvidmar