Reputation: 10548
I'm stuck in very awkward situation where Images are being shown in Local Environment while generating PDF. But, Not in Production. Images being displayed as [X] when to generate PDFs with mPDF.
After inserting $mpdf->showImageErrors = true;
in Controller.
public function actionExportCasesPdf($id) {
.
.
.
.
$mpdf = new \mPDF();
$mpdf->showImageErrors = true;
$mpdf->WriteHTML($output);
$mpdf->Output($fileName, 'D');
}
Error
MpdfException
IMAGE Error (..17.jpg): Error parsing image file - image type not recognised, and not supported by GD imagecreate
Even, GD library is installed in the server using apt-get install php5-gd
command. And, Image Path are also used correct.
I tried to keep image source as such. But, No Luck.
<img src="<?= \yii\helpers\Url::to('@web/images/logo.png', true) ?>" width="100" alt="logo" />
I searched and tried the solution given by these links. But, still no luck :
Any help/hint/suggestion is appreciable.
Upvotes: 5
Views: 12680
Reputation: 796
Special case
In my case my SSL certificate got expire so I renewed it. My application is hosted on AWS ( classic load balancer).
After upgrading SSL certificate everything start working but MPDF start giving error for image files.
After 3-4 hours I just try with delete ssl certificate using AWS Certificate Manager and import again same certificate. Magic happen and now its working.
Upvotes: 0
Reputation: 56
if you use cpanel on your server go to Hotlink Protection and active Allow direct requests (for example, when you enter the URL of an image in a browser). but your Privacy Policy must allow it screenshot form this section
Upvotes: 0
Reputation: 189
mpdf is not fetching transparent image while generating pdf, so make sure your image is not transparent.
It's working on my localhost but issue with aws server. Apart from aws it's work fine. Gd library is not allow to parse transparent iamge.
Upvotes: 3
Reputation: 10548
It throws one new error
failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized
So, problem was : server was secured with password. So, I searched for it to find the way. And, File-get-contents failed to open stream Unauthorized is having correct answer related to above error.
http://user_name:password@your_site.com/append_your_url
After appending user name
, password
and site name
as above, It worked correctly.
Related Search
Upvotes: 4
Reputation: 1592
Most probably the picture is not available for MPDF via the generated URL. Let's try to debug it :) Run the following code on both local and prod environments
$imageUrl = \yii\helpers\Url::to('@web/images/logo.png', true);
$image = file_get_contents($imageUrl);
echo (new \finfo())->buffer($image);
// echo $image;
// ^^ uncomment, if previous line echoed something not image-related.
// Maybe, you've got 404 error
Upvotes: 3