I've finally gotten around to setting up a completely separate environment for debugging this issue. And so far, all I've been able to produce was a completely blank PDF, while the HTML output works as expected without warnings, errors or exceptions.
Here is my code:
index.php
<?php
require_once "reports/SolarSystemReport.php";
$solarSystemReport = new SolarSystemReport();
switch (filter_input(INPUT_GET, 'export')) {
default:
case 'html': {
$solarSystemReport->run()->render();
break;
}
case 'pdf': {
$solarSystemReport->run();
$solarSystemReport->export()->pdf()->toBrowser('SolarSystem.pdf');
break;
}
}
SolarSystemReport.php
<?php
require_once "vendor/autoload.php";
use koolreport\export\Exportable;
use koolreport\KoolReport;
class SolarSystemReport extends KoolReport
{
use Exportable;
public function settings() {
return [
"dataSources" => [
"planets" => [
"class" => "\koolreport\datasources\ArrayDataSource",
"dataFormat" => "associate",
"data" => [
["name" => "Mercury", "distanceFromSun" => "57909175", "inclination" => "7.00", "rings" => false],
["name" => "Venus", "distanceFromSun" => "108208930", "inclination" => "3.39", "rings" => false],
["name" => "Earth", "distanceFromSun" => "149597890", "inclination" => "0", "rings" => false],
["name" => "Mars", "distanceFromSun" => "227936640", "inclination" => "1.85", "rings" => false],
["name" => "Jupiter", "distanceFromSun" => "778412010", "inclination" => "1.31", "rings" => true],
["name" => "Saturn", "distanceFromSun" => "1426725400", "inclination" => "2.48", "rings" => true],
["name" => "Uranus", "distanceFromSun" => "2870972200", "inclination" => "0.76", "rings" => true],
["name" => "Neptune", "distanceFromSun" => "4498252900", "inclination" => "1.77", "rings" => true]
]
],
"stars" => [
"class" => "\koolreport\datasources\ArrayDataSource",
"dataFormat" => "associate",
"data" => [
["name" => "Sun", "distanceFromGalacticCenter" => ["coefficient" => "2.5", "exponent" => "17"]]
]
]
]
];
}
public function setup() {
$this->src('planets')->pipe($this->dataStore('planets'));
}
}
SolarSystemReport.view.php
<?php
require_once "vendor/autoload.php";
use koolreport\widgets\koolphp\Table;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>KoolreportDebug</title>
</head>
<body>
<div class='page-header'>
<span style="float:right">{pageNum}/{numPages}</span>
</div>
<div class='page-footer'>
<span style="float:right">{pageNum}/{numPages}</span>
</div>
<div class="text-center">
<h1>Solar system report</h1>
<h4>This report shows the planets of our solar system!</h4>
</div>
<hr/>
<div>
<?php
Table::create(array(
"dataStore" => $this->dataStore('planets'),
"columns" => array(
"name" => array(
"label" => "Name"
),
"distanceFromSun" => array(
"type" => "number",
"label" => "Distance from Sun",
"suffix" => " km",
),
"rings" => [
"type" => "boolean",
"label" => "Rings"
]
),
"cssClass" => array(
"table" => "table table-hover table-bordered"
)
));
?>
</div>
</body>
</html>
This issue is turning into a real problem as other departments are asking for automated reports via mail and therefore a PDF export is much needed.
Any suggestions are appreciated!