KoolReport's Forum

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

PDF Exporting ChartJS Not Appear In the pdf #2611

Open BAERT opened this topic on on Mar 11, 2022 - 4 comments

BAERT commented on Mar 11, 2022

Hey,

I use KoolReport on Symfony with the Package Exportable but I don't succed to get a chart on a pdf. However I can display different chart on a web page.

It is my follow code:

        $report = new \App\Reports\MyReport;
        $report->run()
        ->export('MyReportPDF')
        ->settings()
        ->pdf(array(
            "format"=>"A4",
            "orientation"=>"portrait",
        ))
        ->toBrowser("test.pdf");

MyReport.php

use \koolreport\KoolReport;
use \koolreport\processes\TimeBucket;
use \koolreport\processes\Group;

//Step 2: Creating Report class
class MyReport extends \koolreport\KoolReport
{
	// use \koolreport\clients\Bootstrap;
    use \koolreport\export\Exportable;
	
    public function settings()
    {
        return array(
            "dataSources"=>array(
                "sakila_rental"=>array(
                    "class"=>'\koolreport\datasources\CSVDataSource',
                    'filePath'=>dirname(__FILE__)."/sakila_rental.csv",
                )
            )
        );
    }
        
    protected function setup()
    {
        $this->src('data')
        ->pipe($this->dataStore('test'));

        $this->src('sakila_rental')
        ->pipe(new TimeBucket(array(
            "payment_date"=>"month"
        )))
        ->pipe(new Group(array(
            "by"=>"payment_date",
            "sum"=>"amount"
        )))
        ->pipe($this->dataStore('sale_by_month'));
    } 

}

MyReportPdf.view.php

<?php 
    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
        ColumnChart::create(array(
            "dataStore"=>$this->dataStore('sale_by_month'),  
            "columns"=>array(
                "payment_date"=>array(
                    "label"=>"Month",
                    "type"=>"datetime",
                    "format"=>"Y-n",
                    "displayFormat"=>"F, Y",
                ),
                "amount"=>array(
                    "label"=>"Amount",
                    "type"=>"number",
                    "prefix"=>"$",
                )
            ),
            "width"=>"100%",
        ));

        ?>
    </body>
</html>

Did I miss something?

KoolReport commented on Mar 11, 2022

There are two things you can try:

  1. Let try to test exporting outside of Symfony if it works.
  2. Try to increase the resourceWaiting, details

Let me know if it works.

BAERT commented on Mar 12, 2022

It works outside of Symfony. If I increase the resourceWaiting nothing change with Symfony )=

Sebastian Morales commented on Mar 15, 2022

Pls use "useLocalTempFolder" setting when you export like this:

    $report->run()->export("MyReportPDF")
        ->settings([
            'useLocalTempFolder' => true,
        ])
        ->pdf(array(
            ...
        ))
        ->toBrowser("MyReport.pdf");  

Then run export and look for the latest .tmp file in your report folder's tmp subfolder. Change its name to .html and open it in browser to see if there's any missing js, css file (F12 -> tab Network, red lines indicate unloaded resources).

KoolReport commented on Mar 15, 2022

I think you need to configure the assets in settings() function so that your report can export resource to public folder of symfony.

    public function settings()
    {
        return array(
            "assets"=>array(
                "path"=>"../path/to/public/folder",
                "url"=>"/url/to/public/folder"
            ),
            "dataSources"=>array(
                "sakila_rental"=>array(
                    "class"=>'\koolreport\datasources\CSVDataSource',
                    'filePath'=>dirname(__FILE__)."/sakila_rental.csv",
                )
            )
        );
    }

This settings will help KoolReport to export js and css to a public folder of symfony and know how to access those resource from browser.

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