Pdf File Is Not Displayed Properly On Localhost

0

The generated PDF file looks as if it lacks styles, and images are not loaded, even though the logo has been loaded into the application. The invoice status picture is also not visible.

The application runs on localhost, and works fine by itself.

The Apache server alias is set to:
Alias /simple_invoice_manager "d:/www/simple_invoice_manager/www/"
where the first "www" is root for PHP.

Additionally, there are entries in the htaccess file:
RewriteBase /simple_invoice_manager/
and for hosting:
RewriteRule ^(.)$ index.php?/$1 [L]
and for SSL:
RewriteCond %{HTTPS} off
RewriteRule ^(.
)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Let me add that the rule for SSL doesn't break anything.
My PHP version is: 7.3.12

Please help me fix the problem.

Łukasz

Question Resolved For: Simple Invoice Manager - Invoicing Made Easy 0 Votes 14 Answers 1.4k Views
Asked by Łukasz 2 years ago

0

Answered by Mian Saleem 2 years ago

Hello,

Please check allow_url_fopen It should be enabled along with php GD extension.

SSL could cause such issue too. If you have enable ssl then you should set the base_url in app/config/config.php to https:// too.

Thank you

0

Answered by Łukasz 2 years ago

Exactly everything you wrote about, I had already turned on (I still have it turned on).
Also base_url looks like this:
$config['base_url'] = 'https://localhost/simple_invoice_manager/';

I have multiple instances of Wordpress and Prestashop on this localhost, and all the required extensions for the applications are definitely enabled and properly configured as the applications are working fine.

I suppose it's related to localhost, but I don't know where to look for a solution. The application itself, apart from generating complete PDF files, worked flawlessly.

The cause of the problem must be elsewhere.

0

Answered by Mian Saleem 2 years ago

Hello,

If you SSL is install properly on localhost then you can check my other suggestion. You can check both with phpinfo function. You need to be sure about allow_url_fopen and php-gd extension.

Thank you

0

Answered by Łukasz 2 years ago

We already wrote about it, and as I wrote before, I will repeat myself and say the same, I have it turned on.

0

Answered by Łukasz 2 years ago

I waited and waited for the help of real specialists, I waited so much that I finally looked for the cause of the problem myself...

I found the problem on line 124 in the Sim.php file, and it generates this message:

ERROR - 2021-08-19 00:41:27 --> Severity: Warning --> file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed D:\www\simple_invoice_manager\www\app\libraries\Sim.php 124
ERROR - 2021-08-19 00:41:27 --> Severity: Warning --> file_get_contents(): Failed to enable crypto D:\www\simple_invoice_manager\www\app\libraries\Sim.php 124
ERROR - 2021-08-19 00:41:27 --> Severity: Warning --> file_get_contents(https://localhost/simple_invoice_manager/themes/default/assets/img/paid.png): failed to open stream: operation failed D:\www\simple_invoice_manager\www\app\libraries\Sim.php 124

If I am not mistaken, the solution currently used in the get_image() function (and using the PHP file_get_contents() function) may not work properly when we have an application running on Windows using SSL.

It just so happens that in my case the application is supposed to run on Windows using SSL, and the functionality of generating invoices in PDF format is the main reason why I purchased your application.

I found a workaround for this, but it would be nice if a standards-compliant and secure solution would appear in the code in the near future.

Bottom line: I found the cause of the problem, now I am asking you to fix the problem.

Łukasz

0

Answered by Łukasz 2 years ago

P.S. Sorry if I'm too demanding, but I just didn't expect problems with one of the key functionalities of your application, and one that is so crucial to me. It worked fine on your demo, I thought it would work right away. Time is chasing me, and the problem is as it was.

0

Answered by Mian Saleem 2 years ago

Hello,

Yes, looks like the issue is due to SSL on localhost. I have no idea, but maybe you can try to disable ssl and use http:// instead to check.

Thank you

0

Answered by Łukasz 2 years ago
  1. I can't disable SSL because everything I'm working on is set up for SSL.
  2. I don't want to turn it off either, because the target application is supposed to run on a given localhost/IP address and I would prefer the network traffic to be encrypted, even if it's an internal network.
  3. I found a workaround (I used cURL) but it is not safe as I stopping cURL from verifying the peer's certificate. I think it can be done nicely, consistently for each type of environment and most importantly for keeping the application secure. You probably need to use a different way to get the resource content than file_get_contents() function.
  4. Additionally, I believe the problem is more global and could be with any function that uses file_get_contents () to get a resource.
  5. Maybe this will help you to prepare the solution: https://www.php.net/manual/en/function.file-get-contents.php#refsect1-function.file-get-contents-notes

Best regards
Łukasz

0

Answered by Mian Saleem 2 years ago

Hello,

  1. I am not sure but try to set the base_url to http:// and access it with http:// I think you should be able to test if the issue is due to SSL or not.

  2. I don't know your setup but guess that you have set the base_url to Server IP or some sort of port forwarding. If not you can try to change and see if it make any difference.

file_get_contents with ssl could the real cause with no alternate as dompdf is used to generate pdfs, which uses file_get_contents 😦

Thank you

0

Answered by Łukasz 2 years ago
  1. When I started to find the reason, I checked whether the PDF invoice generator worked without problems via http. And yes, there are no problems without SSL.
  2. So far, the problem is on secured localhost. Ultimately, a separate VirtualHost will be configured for the application, which means that the problem will be exactly the same as with localhost.
  3. As mentioned before, I created a function where I use cURL, and it works fine, but it's not completely secure.
  4. As for dompdf, it may be worth overwriting some of the code of this library, or report the problem to the creators of this library.
  5. Unless ultimately the application receives an annotation that it has problems in a given situation, then no one will require proper operation in such configuration 😦
  6. To be completely honest, aside from the fact that this issue occurs, the app is great. That's why I hope it will be improved 😃

Best regards
Łukasz

We use Cookies

We use cookies to ensure that we give you the best experience on our website. By continuing to browse the site you are agreeing to our use of cookies.