KoolReport's Forum

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

Trouble Exporting Data tables and Chart Js with chrome headless IO #2850

Open iWorQ Systems opened this topic on on Oct 20, 2022 - 11 comments

iWorQ Systems commented on Oct 20, 2022

I am trying to export a Data table and Js Donut chart to a PDF using chrome headless IO. When I print the report, the graph does not show up, and the data table is not formatted correctly. Just checking to see what I am doing incorrectly.

Export.php

error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once "CodeActivityGraphList.php";
$date = date('m/d/Y');
$text = 'WorkLogReport' . $date . '.xls';
$date1 = $_GET['date1'];
$date2 = $_GET['date2'];
$dateField = $_GET['dateField'];
$typeStatus = $_GET['typeStatus'];
$settings = [
	"pageWaiting" => "networkidle2", //load, domcontentloaded, networkidle0, networkidle2
];
$pdfOptions = [
    "format"=>"A4",
    'landscape'=>false,
    "noRepeatTableFooter" => true,
];
$report = new CodeActivityGraphList(['date1' => $date1, 'date2' => $date2, "dateField" => $dateField, "typeStatus" => $typeStatus]);
$report->run();
$report
->cloudExport("CodeActivityGraphPdf")
->chromeHeadlessio("mytoken")
->settings($settings)
->pdf($pdfOptions)
->toBrowser("CodeActivityGraphReport.pdf");

CodeActivityGraphPdf.view.php

    use koolreport\datagrid\DataTables;
    use koolreport\chartjs\DonutChart;

    $sid = $_GET['sid'];
    $fid = $_GET['fid'];
    $aid = $_GET['aid'];
    $date1 = $this->params['date1'];
    $date2 = $this->params['date2'];
    $dateField = $this->params['dateField'];
    $typeStatus = $this->params['typeStatus'];
?>

<style>
    .tables{
        text-align: center;
        text-decoration: underline;
    }
    * {
        -webkit-print-color-adjust: exact !important;
      }

</style>
<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="text-center">
<h1 class="tables">Code Activity Table</h1>
    <div style="width: 45%;
    top:0;
    bottom: 0;
    left: 0;
    right: 0;
    
    margin: auto;">
    
    <?php
    if ($typeStatus == 'type') {
        DonutChart::create([
            "title" => "Activity Types",
            "dataSource" => $this->dataStore("typeStatusGraph"),
            "columns" => [
                "Activity Type",
                "Activities" => [
                    "type" => "number"
                ]
            ]
        ]);
        ?>
            </div>
            <br>
            <br>
            <div style="width: 80%;
            top:0;
            bottom: 0;
            left: 0;
            right: 0;
            margin: auto;">
        <?php
        DataTables::create([
            "dataStore" => $this->dataStore("typeStatusTable"),
            "columns" => [
                "Case #",
                "Activity Type",
                "Activity Date",
                "Scheduled Date",
                "Completed Date",
                "Description",
                    
            ],
            "cssClass" => [
                "table" => "table table-bordered table-striped table-hover"
            ]
        ]);
        
        ?>
        </div>
            <?php
    } else {
        DonutChart::create([
            "title" => "Activity Status",
            "dataSource" => $this->dataStore("typeStatusGraph"),
            "columns" => [
                "Status",
                "Activities" => [
                    "type" => "number"
                ]
            ]
        ]);
        ?>
            </div>
            <br>
            <br>
            <div style="width: 80%;
            top:0;
            bottom: 0;
            left: 0;
            right: 0;
            margin: auto;">
        <?php
        DataTables::create([
            "dataStore" => $this->dataStore("typeStatusTable"),
            "columns" => [
                "Case #",
                "Status",
                "Activity Date",
                "Scheduled Date",
                "Completed Date",
                "Description",
            ],
            "cssClass" => [
                "table" => "table table-bordered table-striped table-hover"
            ]
        ]);
    }
    ?>
</div>
</body>
</html>


Any help would be great, thank you.

Sebastian Morales commented on Oct 21, 2022

Pls use "useLocalTempFolder" => true in your export settings:

$settings = [
	"pageWaiting" => "networkidle2", //load, domcontentloaded, networkidle0, networkidle2
        "useLocalTempFolder" => true,
];

Then try export and check for the latest zip file/subdirectory in your report's local "tmp" directory. Open the file export.html/index.html there on your browser and see if charts appears or tables have style. If not pls open dev tool (F12) and let us know if there's any error (like loading js, css or js error). Tks,

iWorQ Systems commented on Oct 21, 2022

looks like none of the styles or scripts are loading in/ being put in.

Sebastian Morales commented on Oct 24, 2022

Can you pls right click the failed to load js files and check their url path to see why they are not loaded? Tks,

iWorQ Systems commented on Oct 24, 2022

there is no source at all. I'm guessing that is the problem.

iWorQ Systems commented on Oct 24, 2022

When trying load the path is just to the temp file. not to the koolreports composer file

Sebastian Morales commented on Oct 26, 2022

Do you use reports in any framework such as Laravel, Symphony, etc? And did the table and chart shown correctly in your report web view?

iWorQ Systems commented on Oct 26, 2022

I am not using a framework. and yes the report itself is showing up.

iWorQ Systems commented on Oct 27, 2022

So I have noticed that this is only a problem on my Local, and not on our live product. Do you know where the paths for the js and css are getting set for the PDF export for the CromeHeadlessIO? I need to be able to test these things on my local, and I am betting that the paths are just not being set right.

Sebastian Morales commented on Oct 31, 2022

Oh I see, which web server do you use for your local development? Rgds,

iWorQ Systems commented on Oct 31, 2022

We use docker running a nginx server

Sebastian Morales commented on Nov 1, 2022

Thanks, I guess this could be a case where cloud export package didn't figure out the true path of js, css of the report. If it's not too much hassle would you pls emailing us the report's html source (right click report web page -> View page source) as well as the local tmp zip created when exporting. We will try to see how cloud export fails in this case. Rgds,

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

CloudExport