KoolReport's Forum

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

Export PDF Bootstrap #3216

Open Martin opened this topic on on Dec 21, 2023 - 23 comments

Martin commented on Dec 21, 2023

Hi,

I'm trying to export in PDF a table with Bootstrap css format. But it does work. I've check everything concerning this problem : phantomjs, etc... When i check the tmp generate with pdf ( rename in html ) , the koolreport.js is not found because for localtion the localhost is missing in the url. I already add : "serverLocalAddress" => "localhost", But does wrok at all. Can i have some help for this issue ? Regards.

KoolReport commented on Dec 24, 2023

Let try to change "serverLocalAddress" => "127.0.0.1" to see how as the localhost not always works.

Martin commented on Dec 24, 2023

Hi,

Already tested, but not worked.

Regards

Martin commented on Dec 24, 2023

Hi,

In the browser network tools i have this error : Uncaught ReferenceError: KoolReport is not defined

Regards

KoolReport commented on Dec 25, 2023

Have you tried to view the report on browser? Does it work well? If possible, please see the html code from browser and see the <script> tag that containing koolreport.js Let check if the url is correct and accessible.

Martin commented on Dec 26, 2023

Hi, Yes, it is precisely on the Browser that I have this error ( after rename the tmp file ). Here is the script part:

<script type='text/javascript' src='/myapp/dev/koolreport/core/src/clients/core/KoolReport.js'></script><script type='text/javascript'>KoolReport.load.resources({"js":["\/myapp\/dev\/koolreport\/core\/src\/clients\/jquery\/jquery.min.js",["\/myapp\/dev\/koolreport\/bootstrap4\/assets\/core\/js\/bootstrap.bundle.min.js"]],"css":["\/myapp\/dev\/koolreport\/bootstrap4\/assets\/core\/css\/bootstrap.min.css"]});</script>

Regards

Martin commented on Dec 28, 2023

Hi, Any news about this issue ?

Best regards

Sebastian Morales commented on Jan 2

I think the script src might have a problem because src='/myapp/dev/koolreport/core/src/clients/core/KoolReport.js' is a file path, not a url one. Do you use a framework such as Laravel, Symphony, etc and would you mind posting your report php code for us to check the setting for you? Tks,

Martin commented on Jan 3

Hi, I do not use framework. This src is relative path for script , so must work as well as for all. I already try with the tmp file to replace with the full url , but same problem !

Martin commented on Jan 3

Hi again. I tested again the tmp file and updated all path with the full url ( host .... + path ) and it works. So now , how can i do to generate my pdf and set correct path ? But i do not understand why the views works well ?

Sebastian Morales commented on Jan 4

Pls update your PDF view to use the same url paths as your web view. Then check the generated .tmp files to make sure they have correct url paths to js and css files. If they still have wrong paths pls post your report class, view, and PDF view files for us to check them for you.

Martin commented on Jan 4

Hi, There is something i do not understand ! the pdf is generated in a tmp folder ( as tmp file ). So all path are bad because tmp folder is a child folder. So all path must be like this ../ + PATH What do you think about ?

Sebastian Morales commented on Jan 4

The .tmp file generated when exporting to PDF must have the exact url path as the report view file even if their locations are different. The PDF rendering engine of package Export will only use the .tmp file content and not its location to render its content to PDF.

Martin commented on Jan 4

In all my development with KoolReport, access to resources is with relative paths. How do I specify an absolute URL?

Martin commented on Jan 4

Has anyone successfully exported a PDF with Bootstrap and Koolreport? I've been trying to solve this problem for 3 weeks!

Sebastian Morales commented on Jan 4

Pls post your report setup and view code. We will check the resource path for you. Tks,

Martin commented on Jan 4

// 1st Courbe_Prev15j.php

<?php

require_once "CourbePrev15j.php";


$CourbePrev15j = new CourbePrev15j(array(
    "data"=>$data_source,));

$CourbePrev15j->run()->render();



?> 

// 2nd CourbePrev15j.php

<?php

require_once "koolreport/core/autoload.php";
use \koolreport\KoolReport;
use \koolreport\processes\Group;
use \koolreport\processes\Sort;
use \koolreport\processes\Limit;

class CourbePrev15j extends KoolReport
{
	 use \koolreport\export\Exportable;
	 use \koolreport\bootstrap4\Theme;
	 
    public function settings()
    {
    	  
        return array(
            "dataSources"=>array(
                "mydata"=>array(
                    "class"=>'\koolreport\datasources\ArrayDataSource',
                    "data"=>$this->params["data"],
                    "dataFormat"=>"associate",
                )
            )
        );
    }

    public function setup()
    {
        $this->src('mydata')
        ->pipe(new Sort(array("date"=>"asc",))) 
        ->pipe($this->dataStore('courbe_prev15j'));

    }
    
    
}



?> 

// 3rd CourbePrev15j.view.php

<?php 
    use \koolreport\widgets\koolphp\Table;
    use \koolreport\widgets\google\LineChart;
?>

<?php

 
    LineChart::create(array(
    "title"=>"",
    "dataSource"=>$this->dataStore('courbe_prev15j'),
    "options"=>array(
        "curveType"=>"function"
    ),
        "columns"=>array(
            "date"=>array(
            "type"=>"date",
            "xFormat"=>"%Y%m%d",
            "xDisplayFormat"=>"%B %d, %Y"),
            "predic"=>array(
                "label"=>"Prevision",
                "type"=>"number",
                "prefix"=>"W"
            ),
        )
));    
    
   

?>

// 4th export_prev15j.php

<?php

require_once "report/CourbePrev15j.php";
$report = new CourbePrev15j(array(
    "data"=>$data_source,));

    
$report->run()
->export('CourbePrev15jPdf')
->settings([
    "useLocalTempFolder" => true,
    "serverLocalAddress" => "127.0.0.1",
])
->pdf(array(
    "format"=>"A4",
    "orientation"=>"portrait",
    //"zoom"=>2
))
//->toBrowser("courbe_predic.pdf",true);
->saveAs("tmp/courbe_predic.pdf");


?>


// 5th CourbePrev15jPdf.view.php


<?php 
    use \koolreport\widgets\koolphp\Table;
    use \koolreport\widgets\google\LineChart;
    use \koolreport\bootstrap4\Theme;
?>
<html>

<head>

<style>
* {
    -webkit-print-color-adjust: exact !important;
}

@media print {
    * {
        -webkit-print-color-adjust: exact !important;
    }    
}
</style>

</head>
    
    <body style="margin:1in"> 


        <?php
        
        
    LineChart::create(array(
    "title"=>"",
    "dataSource"=>$this->dataStore('courbe_prev15j'),
    "options"=>array(
        "curveType"=>"function"
    ),
        "columns"=>array(
            "date" =>array(
            "type"=>"date",
            "xFormat"=>"%Y%m%d",
            "xDisplayFormat"=>"%B %d, %Y"),
            "predic"=>array(
                "label"=>"Prevision",
                "type"=>"number",
                "prefix"=>"W"
            ),
        )
)); 

        ?>
        
        <hr/>
            <?php
    
    
    Table::create(array(
    "dataStore"=>$this->dataStore("courbe_prev15j"),
    "columns"=>array(
            "date"=>array(
                "label"=>"Date"
            ),
            "predic"=>array(
                "label"=>"Prévision"
            )
        ),
    "cssClass"=>array(
            "table"=>"table",
            "thead"=>"thead-dark"
        )    
    ));
    
    ?>
    
    
    </body>
</html>
Sebastian Morales commented on Jan 5

I don't see any problem with your report setting. Would you pls rename the .tmp file to .html and copy it to the same directory as your report view file. Then open the renamed .html file in your browser to see if its css loads or not and the reason if css is not loaded.

Martin commented on Jan 5

Hi, I added this morning a card with bootsrap class, and it's work for the card ! Here :

    Card::create(array(
        "value"=>$this->dataStore("courbe_prev15j")->slice(4,1)->only("predic"),
        "format"=>array(
            "value"=>array(
                "prefix"=>"Wh"
            )
        ),
        "title"=>"Prevision",
        "cssClass"=>array(
            "card"=>"bg-primary",
            "title"=>"text-white",
            "value"=>"text-white"
        )
    ));

So i think tere is something wrong with Table objet ?

Sebastian Morales commented on Jan 8

Can not know for sure. We need to know if each step is correct. Pls follow my previous post and let us know the result.

"Would you pls rename the .tmp file to .html and copy it to the same directory as your report view file. Then open the renamed .html file in your browser to see if its css loads or not and the reason if css is not loaded."

Martin commented on Jan 8

Hi, If i copy the tmp in my Report folder ( where the view is ) and rename it in html , it works ( in the browser ) for cards & table. So what's the problem ? And what i need to do ? Regards.

Sebastian Morales commented on Jan 9

Would you pls post screenshot of the PDF file that Bootstrap css doesn't work. By the way, pls try our standard export example on your server/localhost and see if its Table css works:

https://www.koolreport.com/examples/reports/export/sakila_rental/

Martin commented on Jan 10

Hi,

Your example work, but it is a simple table, without any color etc.... What i think it is not a good idea to use bootstrap with export package, because grid, colors not work well. I only succed a great table , or layout wtih css embedded in the page. I test now other chart with export package : Google work well , but ApexCharts do not ! I'm a little disappointed. Regards

Sebastian Morales commented on Jan 11

Please try our CloudExport to export the ApexCharts, CloudExport is more advanced with Chromeheadless and compatible with new JS technology (that used in ApexCharts) than in Export package with Phantomjs.

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
None yet

None