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