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

alcomcomputing picture alcomcomputing · May 7, 2014 · Viewed 20.7k times · Source

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" />

Answer

user3870773 picture user3870773 · Jul 24, 2014

I ran across this issue today. My problem was that the domain name I was using didn't resolve back to the server when accessed from the server. I added an entry to the hosts file on the server, and images started showing.

Your equivalent hosts file entry of what fixed my problem would be:

127.0.0.1 www.aibsonline.co.uk

Or otherwise ensure that www.aibsonline.co.uk resolves to your server in the DNS that your server uses.

It appears that mPDF accesses images as a cURL web client, so DNS on the server needs to be configured correctly to refer back to itself.