KoolReport's Forum

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

Exporting PDF is blank #733

Open Les Hoffman opened this topic on on Mar 8, 2019 - 18 comments

Les Hoffman commented on Mar 8, 2019

I have at a lot of success running Koolreports and exporting PDF's but I have an unusual problem that I can't solve.

The code I have written works perfectly on several servers that I'm using for production. They are all under Ubuntu 16.04. My live server running on VMWare runs the scripts perfectly but the Export to PDF produces a blank page.

I have compared using phpinfo my production server vs. live server and they are both identical. Can there be a compatibility issue with phantomjs on the live server for some reason?

What do you suggest I do?

KoolReport commented on Mar 9, 2019

On your live server, if you run the "phantomjs -v" in the folder "export/bin". Does it print the version of phantomjs.

Les Hoffman commented on Mar 9, 2019

Yes it does. Version is 2.1.1. I have also executed at the command line a phantomjs test script which works properly. Under my Koolreport it produces a pdf file of 1.2K which is blank. On my production server it's 25K as it should be.

KoolReport commented on Mar 9, 2019

Let try to make a small test with a blank report, no data connection, no data processes, only a view with simple html like:

<html>
    <body>
        Helloworld!
    <body>
</html>

Let see if it works.

Les Hoffman commented on Mar 9, 2019

As a quick test I replaced SakilaRentalPdf.view.php in your examples with your suggested HTML. Result was a blank page on my live server.

I did the same on my production server which worked properly.

KoolReport commented on Mar 9, 2019

I guess your live server lack of some updated library which required by PhantomJS. Please try to follow this guide to install phantomjs on your server:

https://gist.github.com/telbiyski/ec56a92d7114b8631c906c18064ce620

If you do install like above, in order for Export package to locate phantomjs, you need to use the extra settings to set the phantomjs execution path. You only need:

->settings(array(
    "phantomjs"=>"/path/to/phantomjs",
))
KoolReport commented on Mar 9, 2019

By the way, please try the following

sudo apt-get update
sudo apt-get install build-essential chrpath libssl-dev libxft-dev -y
sudo apt-get install libfreetype6 libfreetype6-dev -y
sudo apt-get install libfontconfig1 libfontconfig1-dev -y

and then try to run Export to see if it work first. If not then continue the rest.

cd ~
export PHANTOM_JS="phantomjs-2.1.1-linux-x86_64"
wget https://github.com/Medium/phantomjs/releases/download/v2.1.1/$PHANTOM_JS.tar.bz2
sudo tar xvjf $PHANTOM_JS.tar.bz2
sudo mv $PHANTOM_JS /usr/local/share
sudo ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin
phantomjs --version
Les Hoffman commented on Mar 10, 2019

I went through the install of phantomjs and updated export.php as follows: <?php ini_set('display_errors', 1); //error_reporting(E_ALL); ini_set("display_errors", 1);

require_once "SakilaRental.php"; $report = new SakilaRental;

$report->run() ->export('SakilaRentalPdf') ->settings(array(

    "phantomjs"=>"/usr/local/bin",

)) ->pdf(array(

"format"=>"A4",
"orientation"=>"portrait",
//"zoom"=>2

)) ->toBrowser("sakila_rental.pdf, true");

I received the following error: Fatal error: Uncaught Exception: Could not execute phantomjs in /var/www/html/koolreport/packages/export/Handler.php:72 Stack trace: #0 /var/www/html/koolreport/packages/export/Handler.php(237): koolreport\export\Handler->runPhantom('/var/www/html/k...', '/tmp/5c846a2383...', '/tmp/5c846a2383...', 'eyJmb3JtYXQiOiJ...') #1 /var/www/html/examples/reports/export/sakila_rental/export.php(15): koolreport\export\Handler->pdf(Array) #2 {main} thrown in /var/www/html/koolreport/packages/export/Handler.php on line 72

Listing for phantomjs is as follows: lrwxrwxrwx 1 root root 59 Mar 9 20:22 /usr/local/bin/phantomjs -> /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs

KoolReport commented on Mar 10, 2019

You set

"phantomjs"=>"/usr/local/bin/phantomjs",

Let me know if it works

Les Hoffman commented on Mar 10, 2019

Error is gone now but generated PDF is still blank page.

KoolReport commented on Mar 10, 2019

Oh, that's crazy. Let take our previous test with simple view. If you turn on error reporting with error_reporting(E_ALL) and then remove the ->toBrowser() line of code. Let try to run and see any error showing.

Les Hoffman commented on Mar 10, 2019

I know this is super crazy! I've been trying for days to get this to work. Last test just loaded export.php in browser window with no errors showing or in error.log

This is the only server I have problems with and it started from a brand new build of Ubuntu from the ISO in VMWare.

KoolReport commented on Mar 11, 2019

Could you please check if shell_exec() is turned off as we use this command to run phantomjs.

Les Hoffman commented on Mar 11, 2019

It is not disabled. BTW, the tmp directory is filled with .tmp and .pdf files. phantomjs is generating a pdf only it's blank.

Does phantomjs make any external calls to URL's that you know of? Perhaps there is not a correct path back and as well the network is restricted.

KoolReport commented on Mar 11, 2019

No PhantomJs work totally offline, it does not make any call to any url. I am running out of ideas what might go wrong. I am about to suggest you to test the CloudExport package. One of reasons we created CloudExport is to eliminate those issues like this. However, is your live server restricted,?how restricted is it? Is it able to communicate with other server outside. The CloudExport will require the server to communicate with Chomeheadless.io to generate PDF. If you are able to use cloudexport, you will never be worry about installation issue like this.

Les Hoffman commented on Mar 11, 2019

I think that I may have found the problem. You do actually use an external URL. It's the page view that is the external source. My server is setup under NAT. The public IP is restricted to certain IP's. The internal IP of the server is requesting the public version of the page and times out because it's not in the access list.

It can't render it (same problem with wget I just found).

Is it possible to force the use of the internal IP instead of the one found in the URL of the page?

KoolReport commented on Mar 11, 2019

I see, that's correct that we assume the server can access to itself through its domain name. Let me ask the dev.team to find solution for you. Maybe some tweak so that you may have extra options to set this. But what I am little concerned that you will have to maintain two source-codes, one for production and one for live server ( as for live server you will need to set the internal ip).

Another option is that you change inside our code. You can go to line 172 of /packages/export/Handler.php. There you will see the $_SERVER['HTTP_HOST'], you can hardcode your internal ip there. I think this solution is better compare to above solution.

Les Hoffman commented on Mar 11, 2019

I found a way in Handler.php by altering the function getFullUrl() and setting $http_host = my local IP and now it is working.

Thanks for all your help. Amazing support and amazing product. Learned something about network security. Might consider making it a settable parameter in future.

KoolReport commented on Mar 12, 2019

Awesome! What a relief! We also have learned something very new to help other customers.

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
help needed
solved

Export