KoolReport's Forum

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

How to install Export package? #1870

Open Vittorio opened this topic on on Jan 25, 2021 - 12 comments

Vittorio commented on Jan 25, 2021

Hi,

I have tried many times to export a table to pdf: no success at all. This the result shown:

Please note that browser view works perfecly.

Thank you

KoolReport commented on Jan 25, 2021

Above image is the generated pdf, isn't it? Could you please post your code of pdf generating.

Vittorio commented on Jan 26, 2021

Hi,

Please find full code.

Thank you for supporting. Vittorio

index.php
<?php
$tourop= $_POST["tourop"];
$incstaff=$_POST["incstaff"];
$anno=$_POST['anno'];

$dayarr = $_POST["dayarr"];
$montharr = $_POST["montharr"];
$yeararr=$_POST["yeararr"];
$dep=$_POST["arr"];

//echo $arr;
$datadep=$dep;
//echo $datadep;


require_once "Departures.php";
$report = new Departures(array(
    "datasel"=>$datadep,
    "tourop"=>$tourop,
    "anno"=>$anno
));
$report->run()->render();

?>

Arrivals.php
<?php
require_once "../koolreport/core/autoload.php";

use \koolreport\KoolReport;
use \koolreport\processes\Group;
use \koolreport\processes\Sort;
use \koolreport\processes\Limit;


//Define the class
class Arrivals extends \koolreport\KoolReport
{
    use \koolreport\amazing\Theme;
    use \koolreport\export\Exportable;

    public function settings()
    {

        return array(
            "dataSources"=>array(
                "arrivals"=>array(
                    'connectionString' => 'connString',
                    'username' => 'uid',
                    'password' => 'pwd',
                    'charset' => 'utf8',
                ))
        );
    }

     protected function setup()
    {
        //Select the data source then pipe data through various process
        //until it reach the end which is the dataStore named "arrivals".
        $this->src('arrivals')
            ->query("
            SELECT 
                  `rclientiprenota2021`.`idprenota`,
                  group_concat(`clienti`.`cognome` separator ' / ') AS `Names`,
                  `prenota2021`.`idappartamenti`,
                  `periodi2021`.`datainizio` ,
                  `periodi20211`.`datafine` ,
                  SUBSTRING(`prenota2021`.`cat_persone`,LOCATE('<0>',`prenota2021`.`cat_persone`)+3,1) as Adu,
                  SUBSTRING(`prenota2021`.`cat_persone`,LOCATE('<1>',`prenota2021`.`cat_persone`)+3,1) as Chd,
                  SUBSTRING(`prenota2021`.`cat_persone`,LOCATE('<2>',`prenota2021`.`cat_persone`)+3,1) as Inf,  
                  SUBSTRING_INDEX(`prenota2021`.`commento`,'Treatment<',-1) as Arr,
                  `prenota2021`.`origine` AS Origin,
                  SUBSTRING_INDEX(`prenota2021`.`commento`,'>>>Treatment<',1) as Notes,
                  IF (ISNULL(`prenota2021`.`checkin`),
                      '',
                      DATE_FORMAT(`prenota2021`.`checkin`,'%h:%i %p')) As CheckIn
                FROM
                  `rclientiprenota2021`
                  INNER JOIN `clienti` ON (`rclientiprenota2021`.`idclienti` = `clienti`.`idclienti`)
                  INNER JOIN `prenota2021` ON (`rclientiprenota2021`.`idprenota` = `prenota2021`.`idprenota`)
                  INNER JOIN `periodi2021` ON (`prenota2021`.`iddatainizio` = `periodi2021`.`idperiodi`)
                  INNER JOIN `periodi2021` `periodi20211` ON (`prenota2021`.`iddatafine` = `periodi20211`.`idperiodi`)
                WHERE
                  `periodi2021`.`datainizio` =:datasel
                GROUP BY
                  `rclientiprenota2021`.`idprenota`,
                  `prenota2021`.`idappartamenti`,
                  `periodi2021`.`datainizio`,
                  `periodi20211`.`datafine`,
                  `prenota2021`.`num_persone`,
                  `prenota2021`.`origine`,
                  `prenota2021`.`commento`,
                  `prenota2021`.`checkin`
                ORDER BY
                  `prenota2021`.`idappartamenti`,
                  `periodi2021`.`datainizio`
            ")
            ->params(array(
                ":datasel"=>$this->params["datasel"]
            ))
            ->pipe($this->dataStore('result'));

    }
}
?>


ArrivalsPdf.Vieew.php

<?php
use \koolreport\widgets\koolphp\Table;
//use \koolreport\widgets\google\ColumnChart;
?>
<html>
<body style="margin:0.5in 1in 0.5in 1in">
<link rel="stylesheet" href="../../../assets/bs3/bootstrap.min.css" />
<link rel="stylesheet" href="../../../assets/bs3/bootstrap-theme.min.css" />
<div class="page-header" style="text-align:right"><i>Sakila Rental Report</i></div>
<div class="page-footer" style="text-align:right">{pageNum}</div>
<div class="text-center">
    <h1>Cash In Report</h1>
    <h4>This report show the cash-in report per month</h4>
</div>
<hr/>

<?php
Table::create(array(
    "dataStore"=>$this->dataStore('result'),
    "columns"=>array(
        "Names"=>array(
            "label"=>"Names"
        ),
        "idappartamenti"=>array(
            "label"=>"Room"
        ),
        "datainizio"=>array(
            "label"=>"Arrival"
        ),
        "datafine"=>array(
            "label"=>"Departure"
        ),
        "Origin"=>array(
            "label"=>"Origin"
        ),
        "Adu"=>array(
            "label"=>"ADU"
        ),
        "Chd"=>array(
            "label"=>"CHD"
        ),
        "Inf"=>array(
            "label"=>"INF"
        ),
        "Arr"=>array(
            "label"=>"Arr"
        ),
        "Notes"=>array(
            "label"=>"Note"
        ),
        "CheckIn"=>array(
            "label"=>"Check-In"
        ),


    ),
));
?>
</body>
</html>

export.php 
<?php
require_once "Arrivals.php";
$report = new Arrivals;


$report->run()
    ->export('ArrivalsPdf')
    ->pdf(array(
        "headerCallback" => "function(headerContent, pageNum, numPages){
        if (pageNum == 1) return ''; //don't show header for 1st page
        return headerContent;
    }",
        "footerCallback" => "function(footerContent, pageNum, numPages){
        if (pageNum == 1) return footerContent; 
        return ''; //don't show header for pages other than 1st one
    }",
        "format"=>"A4",
        "orientation"=>"lansdscape",
        //"zoom"=>2
    ))
    ->toBrowser("Arrivals.pdf");
?>

KoolReport commented on Jan 26, 2021

It is very simple bug, please change the file name ArrivalsPdf.Vieew.php to ArrivalsPdf.view.php. The problem is that due to the wrong file name, KoolReport could not find it and render debug view into pdf.

Vittorio commented on Jan 26, 2021

Thank you very much for your reply.

However, I see a new error message: "the page does't work - HTTP ERROR 500"

KoolReport commented on Jan 26, 2021

The 500 is very general, so could you please turn on error reporting with error_reporting(E_ALL) to know what went wrong. You should not test the page with export but try to run this:

$report->run()->render("ArrivalsPdf");

Until you receive no error then you move to export the ArrivalsPdf view to pdf.

Vittorio commented on Jan 27, 2021

I have enables erros catc. This is the result when I try to launch PDF:

Fatal error: Uncaught exception 'Exception' with message 'Could not find phantomjs executed file in bin folder' in /volume1/web/seven2021_koolreport/koolreport/export/Handler.php:55 Stack trace: #0 /volume1/web/seven2021_koolreport/koolreport/export/Handler.php(277): koolreport\export\Handler->runPhantom('/volume1/web/se...', '/var/services/t...', '/var/services/t...', 'eyJoZWFkZXJDYWx...') #1 /volume1/web/seven2021_koolreport/arrivals/export.php(20): koolreport\export\Handler->pdf(Array) #2 {main} thrown in /volume1/web/seven2021_koolreport/koolreport/export/Handler.php on line 55

KoolReport commented on Jan 27, 2021

I see, could you please download the phantomjs, here is the instruction.

Vittorio commented on Jan 27, 2021

This is not very clear for me. I use Synology NAS. I just copied phantomjs in a new folder called bin in koolreport/export. Still pdf doesn't work. Do I have to install phantomjs? How to install? Sorry: I am not familiar with Linux administration.

KoolReport commented on Jan 27, 2021

If you have copied the phantomjs to bin folder, you try to run export again. What do you get?

Vittorio commented on Jan 27, 2021

Same error, just handler.php line now is 71. I use PHP 5.6

Fatal error: Uncaught exception 'Exception' with message 'Could not execute phantomjs' in /volume1/web/seven2021_koolreport/koolreport/export/Handler.php:71 Stack trace: #0 /volume1/web/seven2021_koolreport/koolreport/export/Handler.php(277): koolreport\export\Handler->runPhantom('/volume1/web/se...', '/var/services/t...', '/var/services/t...', 'eyJoZWFkZXJDYWx...') #1 /volume1/web/seven2021_koolreport/arrivals/export.php(20): koolreport\export\Handler->pdf(Array) #2 {main} thrown in /volume1/web/seven2021_koolreport/koolreport/export/Handler.php on line 71

KoolReport commented on Jan 27, 2021

No it is different, now it could not execute, please you chmod to set permission to 755 for the phantomjs, 755 means that allowing file to execute.

Vittorio commented on Jan 27, 2021

I gave permissions and I restarted the server. I still get same message. It is so strange.

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