KoolReport's Forum

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

Calling render() function generates null result on live server #432

Open Gerard van de Ven opened this topic on on Aug 28, 2018 - 5 comments

Gerard van de Ven commented on Aug 28, 2018

Hi,

I have a problem with the export to pdf function. I just moved my development site to the live server. Where things are working fine on the development machine, they are not on the live server. The problem seems to be however with the render() function of the "report". I am using the MyPage example that comes with the installation of the pdf export package. I have updated the handler code as follows, so that I can see what is going on on the live server, with a set of echo's in it:

    protected function saveTempContent()
    {
		echo "Handler: Starting saveTempContent<br />";

		$content = $this->report->render($this->view,true);

        if (!isset($content) ) {
            echo "Handler: Content is null<br />";
        } else if ( empty($content) ) {
            echo "Handler: Content is empty<br />";
        } else {
            echo "Handler: Content rendered : '$content'<br />";
        }

		$source = $this->getTempFolder()."/".Utility::getUniqueId().".tmp";

		echo "Handler: Got temp file name for source. About to save temp file.<br />";

		if(file_put_contents($source, $content))
        {
			echo "Handler: Saved source<br />";
            return $source;
        }
        else
        {
			echo "Handler: Could not save source<br />";
            throw new \Exception("Could not save content to temporary folder");
            return false;
        }
    }

The result is the following:

TestPDF: About to export
TestPDF: About to go to PDF
Handler: Starting saveTempContent
Handler: Content is null
Handler: Got temp file name for source. About to save temp file.
Handler: Could not save source

And as a result I have an empty "tmp" file in my temp folder and nothing is rendered to PDF.

I have changed the MyPage example slightly, but as I said, everything runs fine on the development machine. The content of the mypage.php and mypage.view.php files is as follows:

mypage.php:

<?php
error_reporting(1);
require __DIR__ . "/../vendor/koolphp/koolreport/koolreport/autoload.php";

class MyPage extends \koolreport\KoolReport
{
    use \koolreport\export\Exportable;
}

mypage.view.php:

<html>
    <head>
        <title>Test page</title>
    </head>
    <body>
        <!-- CSS Style -->
        <style>
            p {font-size:20px;}
            h1 {color:red}
        </style>
        <div class="wrapper">
            <h1>Export HTML to PDF</h1>
            <p>It is easy to convert HTML to PDF using KoolReport's Export package</p>
            <p id="extra">To be replaced by JavaScript</p>

            <?php
            $myvar = true;

            if ( $myvar ) {
                echo "PHP is working as well";
            } else {
                echo "PHP is working, but a bit strangely";
            }
			?>

            <!-- Javascript embedded -->
            <script type="text/javascript">
                document.getElementById("extra").innerHTML = "JavaScript is working";
            </script>
            <div class="push"></div>
        </div>
        <footer class="footer">
            <span>Page <some page number can go here></span>
        </footer>
    </body>
</html>

The file that I am running that kickstarts it all: testpdf.php:

<?php
error_reporting(1);
// testpdf.php
require __DIR__ . "/mypage.php";

$mypage = new MyPage;

echo "TestPDF: About to export<br />";
$result = $mypage->export()
    ->settings(array(
    "useLocalTempFolder"=>true
));
echo "TestPDF: About to go to PDF<br />";
$result = $result->pdf(array(
    "format"=>"A4",
    "orientation"=>"portrait"
));
//echo "TestPDF: About to go to Browser<br />";
//$result->toBrowser('mypage.pdf', true);

The server this is running on is a Linux server, running php 5.4.45. My development machine is a Windows 10 laptop, with the site running under IIS.

Does anybody have any ideas? I am stumped at what could go wrong here.

Thanks a lot for your help, this is a breaking issue for us at the moment. And the pdf generation is really important for the site.

Gerard

KoolReport commented on Aug 28, 2018

Hi, please change the filename of your view to MyPage.view.php. In window the filename can be case insensitive but not in other like Linux. So it could be issue causing null because KoolReport could not find the view. Could you please check.

Gerard van de Ven commented on Aug 28, 2018

Thank you! That helped. It now renders the file as expected. I now have a problem that phantomjs is not executing (the check on whether the results contains a ";" in the runPhantom() method in the Handler.php file returns false). But it is probably better if I make another question for that.

KoolReport commented on Aug 29, 2018

Please go to our forum search box and search for phantomjs, you will see many thread related to phantomjs. Basically, your online server will need correct version of phantomjs (for linux or window) and it should have permission to run. In some server, it requires PhantomJS to install, not just copying the file (although this way works 90%).

Gerard van de Ven commented on Aug 30, 2018

Hi,

Yes, thanks. Waking up in the morning I realised as well that I had deployed the windows phantomjs.exe file, together with the whole site, to the linux machine, which of course was never going to work. I just uploaded the linux 64 bit version, just copied it into the bin folder, set up the right execution rights on this file and hop, it is all working now. Thanks so much for your help.

KoolReport commented on Aug 30, 2018

Thank you very much for your tips! Very appreciated.

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