KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Laravel - Export - Pdf Error: Could not execute phantomjs #447

Closed Dimitry opened this topic on on Sep 4, 2018 - 14 comments

Dimitry commented on Sep 4, 2018

Hi. I am having one more issue for today. Sorry abt that pls!

I am using Laravel 5.6 with Docker, Nginx, Php-fpm 7.2, Postgresql on Centos 7.

shell_exec is working

here is where phantom.js:

"/var/www/html/beauty.dev/vendor/koolphp/koolreport/koolreport/packages/export/bin/phantomjs"

I have installed via npm in: "/usr/lib/node_modules/phantomjs/lib/phantom/bin/phantomjs" - same error

Here is the command it trying to execute:

"/usr/lib/node_modules/phantomjs/lib/phantom/bin/phantomjs --ignore-ssl-errors=true /var/www/html/beauty.dev/vendor/koolphp/koolreport/koolreport/packages/export/pdf/pdf.js /var/www/html/beauty.dev/vendor/koolphp/koolreport/koolreport/packages/export/tmp/5b8e6bb0a295c2.tmp /var/www/html/beauty.dev/vendor/koolphp/koolreport/koolreport/packages/export/tmp/5b8e6bb0a2ba73.pdf  here_is_token"

here is my Controller:

   public function getpdf(Request $request)
    {
        $report = new BasicReport();
        $report->run()
            ->export()
            ->settings(array(
                "useLocalTempFolder"=>true,
//                "phantomjs"=>"/usr/lib/node_modules/phantomjs/lib/phantom/bin/phantomjs",
                "resourceWaiting"=>2000,
            ))
            ->pdf(array(
                "format"=>"A4",
                "orientation"=>"portrait"
            ))
            ->toBrowser("report.pdf");
        return view("basicreport",["report"=>$report]);
    }

Here is content of the tmp folder:

ls -l
total 448
-rw-r--r--. 1 33 33 62305 Sep  4 14:14 5b8e6930daef22.tmp
-rw-r--r--. 1 33 33 62305 Sep  4 14:17 5b8e69c9d800b2.tmp
-rw-r--r--. 1 33 33 62305 Sep  4 14:17 5b8e69d8c1ee82.tmp
-rw-r--r--. 1 33 33 62305 Sep  4 14:20 5b8e6a6d54fda2.tmp
-rw-r--r--. 1 33 33 62305 Sep  4 14:24 5b8e6b5140de32.tmp
-rw-r--r--. 1 33 33 62305 Sep  4 14:24 5b8e6b89a0d912.tmp
-rw-r--r--. 1 33 33 62305 Sep  4 14:25 5b8e6bb0a295c2.tmp

But when it tries to save .pdf it throws new \Exception("Could not execute phantomjs");

I am trying to go throw, but if I miss something please let me know.

KoolReport commented on Sep 5, 2018

Please make sure that the phantomjs has permission (755) so it can be executed.

Dimitry commented on Sep 5, 2018

Sure I have :)

ls -l total 66340 -rwxr-xr-x. 1 ddlab wheel 67932064 Jan 25 2016 phantomjs

Any idea? Really confused.

Dimitry commented on Sep 5, 2018

FYI I am able to execute phantomjs from command line directly and save .pdf file of the report.

shell_exec is working, but not able to call phantomjs.

If you have any idea, pls help.

KoolReport commented on Sep 5, 2018

One question: If you run with php, although you will receive the "Could not execute PhantomJs" error but do you see any pdf generated in the temp folder?

Dimitry commented on Sep 5, 2018

Update:

If someone using docker, than add to Dockerfile: RUN apt-get update && apt-get install -y libfontconfig

rebuild php image and use new one.

shell_exec is not verbose, so I have to use console, to find whats wrong.

Now I am able to save pdf, but very ugly and with following errors:

ReferenceError: Can't find variable: $

http://beauty.dev/getpdf:87 in global code ReferenceError: Can't find variable: initPivot

http://beauty.dev/getpdf:1905 in global code 1;/var/www/html/beauty.dev/vendor/koolphp/koolreport/koolreport/packages/export/tmp/5b8fba0f12df23.pdf

Dimitry commented on Sep 5, 2018

If you know what that errors means, pls give me a clue!

KoolReport commented on Sep 5, 2018

The error means that pivot could not load its resources such as js and css. I guess the whole reports could not load client resource. One question: So right now, have you been able to use export package to export the page?

Dimitry commented on Sep 5, 2018

Write now I can export pdf, but almost empty. I was missing libfontconfig on my docker image.

Can you guide me how to solve this errors? Should I change my controller or model?

Dimitry commented on Sep 5, 2018

I can see all view report with js and html inside .tmp file, but .pdf is almost empty, there is no data from report.

KoolReport commented on Sep 5, 2018

Do you use the Laravel package in your report? May be you can share some of your code here.

Dimitry commented on Sep 5, 2018

I use, adn it is working fine on live server with public ip, but not on localmachine.

I am quite fine with that. So we can close this issue.

Thank you very much for your help :)

KoolReport commented on Sep 5, 2018

So using Laravel package solved the last issue. That's great to hear that it is working on live server. What OS do you use on local machine.

Dimitry commented on Sep 5, 2018

Same environment:

Laravel 5.6 with Docker, Nginx, Php-fpm 7.2, Postgresql on Centos 7.

If i will find solution for local machine, I will add here a comment.

KoolReport commented on Sep 5, 2018

That will be great, thank you in advanced.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
solved

None