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

你。 提交于 2019-11-29 06:54:19

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.

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.

alm

With same issue, I found that get_headers() returns:

"HTTP/1.1 412 Precondition Failed"

Provider says this was due to web firewall, because the request was badly formed and the user_agent not set.

An ini_set('user_agent', 'Mozilla/5.0'); solved the problem.

In a WordPress plugin using mpdf, mpdf doesn't use WordPress http classes and doesn't set user_agent. I solved this by adding in mu-plugins:

global $wp_version;

ini_set('user_agent',apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) ));

Just make sure that you have image related functions in your PDF class file. Like parsejpg, parsepng, parsegif etc...

I was running into the same issue. mPDF was running DOG SLOW and would end up just displaying a "Cannot find image file" error. After

  1. checking to make sure the image is actually there
  2. checking the permissions on the file
  3. checking all of the error logs on the server
  4. combing through the documentation on mPDF

I found that the image file in question was corrupted somehow. I downloaded the image to my local computer, opened it up with an image editor (Paint.NET in this case), re-saved it as a .gif file and uploaded it to the server again. That seemed to fix it. Your mileage my vary.

Also, for what its worth, I had to use images/image.gif instead of the file path /images/image.gif.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!