KoolReport's Forum

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

Exporting to PDF is generating blank file #1197

Closed Peter Harari opened this topic on on Dec 2, 2019 - 18 comments

Peter Harari commented on Dec 2, 2019

Hi,

I have recently set up the exporting in my Laravel app with success. It exports to Excel and PDF, both in my local env and in the cloud env as well. Last week only the PDF started to generate a valid PDF file but with a blank page in the cloud env. In my local env is all good.

In the cloud container I executed composer clear-cache followed by composer update. The proccess went fine. Then I checked that vendor/koolreport/export/bin/phantomjs file permissions were -rwx------. I set it to 755 then 777, but neither of them worked.

Here is a sample file of the result I'm getting, if it helps: https://drive.google.com/open?id=1pGbFEZXIp3P03v2zdyHVGGoTW9R3cO24

I don't know where to look at to figure out what is happening, because I don't have an error message/code. Any advice on this ?

Thank you in advance.

KoolReport commented on Dec 2, 2019

Most of environment works by just copying phantomjs to bin folder as we suggested. However in some cases, you need to install phantomjs by command line like this topic. And one more thing, since the phantomjs will not install in the bin, in this case you need to specify the path to phantomjs.

Peter Harari commented on Dec 2, 2019

Hello,

I got it to work until last week, only by downloading the phantomjs binary to the above mentioned path in the container vm. I must say that what you proposed, if really needed, adds complexity in my environment since I deploy in a cloud service, and I'm trying to concentrate everything on composer(as I explained in this topic). I'm not sure how deep I can go in the container to use apt-get neither if I can use apt-get in composer.

There is no other step before trying what you proposed to debug the problem and fix it the way it was working before?

I mean, the PDF is being generated but blank. There is no way to debug/log that process? To the a phantomjs error or something ?

Thank you.

Peter Harari commented on Dec 5, 2019

Hello,

Any news on this ?

Thank you.

KoolReport commented on Dec 9, 2019

If you just make a simple view with only some text in it. Do you receive blank page as well?

Peter Harari commented on Dec 9, 2019

Hello,

Yes, I do get blank page as well.

I created a test report like:

<?php 

namespace App\Reports;

class TestReport extends BaseReport
{
}

As my BaseReport is:

<?php

namespace App\Reports;

use \koolreport\KoolReport;

class BaseReport extends KoolReport
{
    use \koolreport\export\Exportable;
    use \koolreport\excel\ExcelExportable;
}

And a view:

<?php
    $buildVersion = env(\App\Core\EnvParams::HEROKU_RELEASE_VERSION, null);
?>
<html>
    <head>
        <title>Tyto ERP</title>
    </head>
    <body>
        <h1>Relatório Teste</h1>
        <h3>Versão app: <?php echo $buildVersion; ?></h3>
    </body>
</html>

And called it as:

$report = new \App\Reports\TestReport();

$report
    ->export('TestReport')
    ->pdf(array(
        "format" => 'A4',
        "orientation" => 'portrait'
    ))
    ->toBrowser("TestPdfReport.pdf");

And I still got a blank page. Again, the phantomjs binary is on the correct location:

Thank you.

David Winterburn commented on Dec 13, 2019

Hi Peter,

Please open the file KoolReport/export/Handler.php, go to line:

$result = shell_exec($command);

and insert the following line right before it:

echo "command=$command<br>"; exit;

Then run your export again. You should see some output text in the form:

command=path/to/phantomjs.exe --ignore-ssl-errors=true path/to/pdf.js path/to/5df3016fed0b83.tmp path/to/5df3016ff1f074.pdf ...

Check the content of the html file path/to/5df3016fed0b83.tmp. If it's correct copy this command to your terminal to execute it to see if there's any warning. Thanks!

Peter Harari commented on Jan 7, 2020

Hi David,

I'm back at this issue. I'm having hard times to debug like you proposed.

First because the issue is on production, and my vendor folder doesn't goes to the repository. The production CI downloads KoolReport at deploy from a remote repo, so I can't echo that command in my code.

Second problem is that the Heroku CLI doesn't has a text editor by default, so a tried installing vim and nano plugins, but they seem to have some issue themselves. So I can't edit it in the server.

I have checked in Handler.php's code that it creates the output at a temp folder, created like:

mkdir(realpath(dirname(__FILE__))."/tmp");

That should create a tmp folder at the same path as Handler.php, right? Which is vendor/koolreport/export. But there is no tmp folder there.

Do you think this can be the issue ?

Thank you.

David Winterburn commented on Jan 8, 2020

Hi Peter,

With export there're 2 options for location of the tmp folder. The default one is using your server's system temp folder (sys_get_temp_dir()). The second one is creating a tmp folder in your current report's folder, not in the export package folder:

$report
    ->export('TestReport')
    ->settings(array(
        'useLocalTempFolder' => true,
    ))
    ->pdf(

I would suggest you try this option and then check for tmp folder under your report's folder. If it's not there or not created there could be issue with file permission.

Peter Harari commented on Jan 8, 2020

Hi David,

I see now what I missed. I added the setting you proposed but yet it didn't created the tmp folder. I changed all the folders permissions of the path vendor/koolreport/export to 777 but it still the same problem.

Not sure what I can do anymore. Any adivices? I'm researching it meanwhile.

Thank you.

Peter Harari commented on May 25, 2020

Hello.

I need to continue this issue. Still didn't get it to work.

I'm trying to echo something in the PDF creation process, but no success. I replaced the vendor/koolreport/export/Handler.php with this file.

Not that I placed an echo in lines 28, 70(as suggested) and tried to save a more complete log file inside saveTempContent() method. But the PDF is still being generated as a blank file, no matter what.

Any advice?

Peter Harari commented on May 25, 2020

I've set useLocalTempFolder to true but no tmp folder is created(it should be created in the koolreport/export folter right?). So I created it myself, give it 777 permissions. Also for phantomjs binary I set it to 777. But nothing changes.

David Winterburn commented on May 26, 2020

Hi Peter,

When I checked your custom Handler.php file there're these lines in the runPhantom() function:

        echo "command=$command<br>";
	    exit; 
        $result = shell_exec($command);

These would exit the function before executing the pdf converting command. Did you comment out these lines before uploading them to your production?

Another issue is why a local tmp folder wasn't created. I would suggest create a php file in the export package folder with only the following command:

<?php
    mkdir(realpath(dirname(__FILE__))."/tmp");

Then execute it to see if your php user has permission/ability to create a folder inside export.

After that let us know the result. Thanks!

David Winterburn commented on May 26, 2020

Another advice on how to debug the export handler on your production server is to put an echo command after each critical statement. For example:

    ...
    $output = $this->getTempFolder()."/".Util::getUniqueId().".pdf";
    echo "Output  = getTemFolder . getUniqueID . pdf \n";
    ...
    $result = shell_exec($command);
    echo "result = shell_exec $command \n";

And exit the handler instead of return the pdf file to see all the echo commands to get an idea how the handler runs:

    exit;
    return new File($output);

If it did run past the shell_exec command, you could copy the shell_exec command directly to your server's terminal to execute and see its result.

Please let us know if you have any difficulty doing this. Thanks!

Peter Harari commented on May 26, 2020

Hi David.

Thank you for you reply. Help me guess one thing: All changes I made in koolreport/export/Handler.php does not take effect in production environment. I've even removed it, but the outcome is the same, a blank PDF file. I'm using Laravel, could it be some cache(from Composer autoload) or what? Any advice?

KoolReport commented on May 26, 2020

Do you use PHP Built-in Webserver with command like php -S localhost:8000?

David Winterburn commented on May 27, 2020

Hi Peter,

To clear Laravel's cache please try the terminal commands in this page:

https://www.tutsmake.com/laravel-clear-cache-using-artisan-command-cli/

Peter Harari commented on May 27, 2020

Hi all,

For @KoolReport, no I dont use. I use a vagrant machine for local dev and a Heroku free dyno for production testing, where this issue is happening.

For @Davia, thank you again, I will check it out.

Thank you for your answers.

David Winterburn commented on May 28, 2020

Hi Peter,

There's one thing maybe you could try. Please test your vendor/koolreport/export/bin/phantomjs file directly on terminal with this standard example:

https://phantomjs.org/screen-capture.html

Please let us know if it's working out. Thanks!

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

Export