dompdf image not found on live server - php

After several hours of searching, I am still unable to resolve this issue. I am having a problem with displaying images in a PDF file generated by dompdf library.
I have an editor tinyMCE where a user can upload images, edit his page, and see a preview in PDF format with a Button press.
One important thing here: I am using 'convert_urls : true' in tinyMCE's configuration which converts the image src = "https://mysite.com/public/images/image_name.png", necessary for the PDF library to display them.
I set the required dompdf configurations:
def("DOMPDF_ENABLE_REMOTE", true);
Here I found that it will appear after changing the attached CSS with a dompdf like:
img { display:block }
All still in vain.
Note: Everything is working fine on localhost. But on the staging server, I get a message box having a cross inside it saying "image not found" and displaying the image path. When I click on that path, the image is already there on my server. I wonder why dompdf is giving me this message?

I already faced same kind of issue. solution is very simple when Dompdf does not accept url with http format. Try with full document root.
Instead of using https://example.com/public/images/image_name.png try with /var/www/mysite/public/images/image_name.png

Use a absolute path for external css and images than live path! its worked for me also

Related

Is embedding a link to a PHP program in a CSS file safe?

While working on a website I inherited, I was trying to find a background image loaded by the page because it's not stored in the media manager or in the theme's image directory. When I used Chrome's browser inspector to try and download the image, Chrome downloaded a PHP program instead. So, I took a closer look at the CSS file I was inspecting, and found this:
section#headerimg{height:600px;position:relative;z-index:-1;background:url(../images/headers/rotate.php) no-repeat 0 0;background-size:cover;/* Article
Being that this makes it easy to download the PHP source file that calls the image to be displayed rather than the output (the background image), is this a safe thing to do in a CSS file? Is it even valid CSS? Note that this is not a PHP file that generates the CSS file, it's a static CSS file.
chris85 is correct. It turns out my client's hosting provider did not have the permissions set right on my client's account. I contacted the hosting provider and they corrected the issue. Now the referenced PHP file executes as it should. Thank you for your help.

Codeigniter mpdf is not displaying images in live server

I have used mpdf for my codeigniter Project to print ticket with header image and it is working in my local machine while I moved source to test server, the images are not displaying in generated PDF.
Is the Permission issue? Is the invalid SSL issue?
I faced the issue once. You may use the image extension .jpg. It seems mpdf in some live server only accepts .jpeg images. Check with .jpeg images
Note: Don't just manually change the extension. The mime type should be of jpeg image(image/jpeg).

Broken png image using Laravel Asset Pipeline despite 200 OK status

I'm using Codesleeve/asset pipeline on my Laravel project to serve css, js and image files. It on the whole works fine but there is an issue with displaying css-loaded images. The image does not display and shows the browser's "broken image" symbol when loading it directly (http://art.ipscap.com/assets/select2.png for example): e.g.
Upon inspecting the page it shows the image is loaded successfully with 200 OK status (or cached) but there seems to be an error displaying it. Seeing as the image in question displays fine on my local machine and the problem is only in production is there a way to diagnose this issue?
Edit: Still haven' t managed to find a solution for this. For reference the live broken image url is https://art.ipscap.com/assets/select2.png. The image itself is in app/assets/images/select2.png and the readme in the same directory states:
If you place an image here called foobar.png then you can access that image by going to http://<hostname>/assets/foobar.png
I find it strange as the image does not fail to load but is being broken by asset pipeline. The same does not seem to occur to other images in the app such as the header jpeg image.
Do you use different server software on your local and production server? I see the production uses nginx. In that case, you might have to add something to your config as stated here:
https://github.com/CodeSleeve/asset-pipeline#can-i-use-nginx

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

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" />
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.
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' ) ));
I tried all other answers here but for me, only adding
$mpdf->curlAllowUnsafeSslRequests = true;
fixed the issue.
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
checking to make sure the image is actually there
checking the permissions on the file
checking all of the error logs on the server
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.
Just make sure that you have image related functions in your PDF class file. Like parsejpg, parsepng, parsegif etc...
I have password protected server (.htaccess / .passwd) and after some research I understand that mPDF using HTTP to get the images, but server blocks the images from the public because of password protection.
After removing password protection I had ssl certificate issue, and I enable usafe requests and it starts working
$mpdf->curlAllowUnsafeSslRequests = true;
Also you can always enable debug modes and follow the error messages
$mpdf->showImageErrors = true;
$mpdf->debug = true;

mpdf generates pdf without images

I use mpdf for a php project but I am having difficulties generating pdf file with images. it displays the pdf file correctly on browsers but after I save the pdf file it doesnt display the images. I tried it with different browsers/OS and the result is little bit strange to me. it works on very browser and displays local pdf file correctly on linux machine. mac and windows it displays images on every browser but when I save the pdf file it doesnt display the images on local pdf. do you have any idea how to solve this problem.
Thanks
you have to use absolute linking, starting all the way at the top with the domain name.

Categories