KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.

Font and background styles in pdf reports #1037

Open Eugene opened this topic on 7 days ago - 6 comments

Eugene commented 7 days ago

Hi, I've already asked about this in one of my topics but recommended solution does not work.

So what i did:

  • I included all my style inline like this:

"grouping" => array(
            "catName" => array(
                "top" => "<td colspan=\"2\" <td style='color: red'><b>{catName} </b></td>",
  • Also I have added the following style section in the head part of my generated html
<style>
        body {
            -webkit-print-color-adjust: exact;
        }
    </style> 

But the exported pdf is still black and white

David Winterburn commented 6 days ago

Hi Eugene,

Would you please tell us which package did you use to export to PDF, is it Export or CloudExport? Thanks!

Eugene commented 6 days ago

I use CloudExport

Eugene commented 5 days ago

Just noticed that the font-size does not work also... it is almost impossible to make good view report.. :-(

Eugene commented 3 days ago

any ideas?

do your own pdfs keep the css formatting if you use pdf export via CloudExport?

David Winterburn commented 3 days ago

Hi Eugene,

Would you please post the relevant parts of your php code for the report's setup as well as of the pdf view file? Thanks!

Eugene commented 3 days ago

Sure i can but it will be pretty long


require_once "../../koolreport/core/autoload.php";

require_once "spoiled2_export.php";

$report = new spoiled2_export;
$report->run();
$report->cloudExport("spoiled2_export")
    ->chromeHeadlessio("***")
    ->pdf([
        "scale"=>0.6,
        "format"=>"A4",
        "landscape"=>false,
        "displayHeaderFooter"=>true,
        "printBackground"=>true,
        "margin"=>array(
            "top"=>'50px',
            "bottom"=>'40px',
        ),
        "headerTemplate"=> '<div id="header-template"
                style="font-size:7px !important; color:#808080; padding-left:10px">
                Created: <span class="date"></span><br>
                Report name: <span class="title"></span><span></span>
            </div>',
        "footerTemplate"=> '<div id="footer-template"
                style="font-size:7px !important; color:#808080; padding-left:10px">
                Page <span class="pageNumber"></span>
                of <span class="totalPages"></span>
            </div>'
    ])
    ->toBrowser("spoiled_" . date('dmyHi').".pdf");

<?php
// Require autoload.php from koolreport library
require_once "../../koolreport/core/autoload.php";


use \koolreport\processes\CalculatedColumn;
use \koolreport\cube\processes\SuperCube;
use \koolreport\processes\Sort;
use \koolreport\processes\ColumnRename;
use \koolreport\processes\Join;



class spoiled2_export extends \koolreport\KoolReport
{
    use \koolreport\clients\Bootstrap;
    use \koolreport\inputs\Bindable;
    use \koolreport\inputs\POSTBinding;
    use \koolreport\cloudexport\Exportable;


    protected function bindParamsToInputs()
    {
        return array(
            "barmode" => "barmode",
            "date" => "dateInput",
            "reportSelect" => "reportSelect",
            "viewAmount" => "viewAmountbox",
            "viewVs" => "viewVsbox",
            "consumptions" => "consumptions",
        );
    }

    public function settings()
    {
        $config = include "../../config.php";
        return array(
            "dataSources" => array(
                "quinos" => $config["quinos"]
            )
        );
    }

    protected function setup()
    { ... THIS PART IS VERY LONG 
}
<?php
use koolreport\processes\CalculatedColumn;
use \koolreport\widgets\koolphp\Table;

$periode1 = DateTime::createFromFormat("Y-m-d H:i:s", $this->params["dateStart1"])->format("F Y");
$periode2 = DateTime::createFromFormat("Y-m-d H:i:s", $this->params["dateStart2"])->format("F Y");
$stock =  ($this->params["barmode"]) ? 'BAR WAREHOUSE' : 'KITCHEN WAREHOUSE';
$sort_template = array();

if ($this->params["viewAmount"][0] == '1') {
    $sort_template = array(
        "periode - periode2 | total - sum" => "asc");
} elseif ($this->params["viewVs"][0] == '2') {
    $sort_template = array(
        "quantityVS" => "desc");
} else {
    $sort_template = array(
        "name" => "asc");
}

$calculated = $this->dataStore('spoiled')->process(new CalculatedColumn(array(

    "diff_consum" => function ($data) {
        if ($data["consumption1"] == "0") {
            return "N/A";
        } else {
            return ($data["consumption2"] - $data["consumption1"]) / $data["consumption1"] * 100;
        }
    },)));
?>

<html lang="en">
<head>
    <link rel="stylesheet" href="/qreports/koolreport/bootstrap3/assets/core/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="/qreports/koolreport/bootstrap3/assets/core/css/bootstrap-theme.min.css"/>
    <meta charset="UTF-8">
    <title>Spoiled Report</title>
    
</head>
<body style="-webkit-print-color-adjust:exact;">
<div class="container box-container">
    <div class="text-center">
        <h2>Spoiled Report</h2>
    </div>
    <hr/>
    <hr/>
    <div>
        <b>Stock: </b> <?= $stock; ?><br><br>
        <b>Main Periode: </b> <?= $periode2; ?><br><br>
    </div>
    <div class="row">
        <?php
        Table::create(array(
            "dataStore" => $calculated,
            "showFooter" => "top",
            "sorting" =>  $sort_template,
            "columns" => array(
                "name" => array(
                    "label" => "Item Name",
                ),
                "periode - periode1 | quantity - sum" => array(
                    "label" => "Quantity<br>" . $periode1,
                    "formatValue" => function ($value, $row) {
                        $value1 = number_format($value, 2, '.', ',') . " " . $row["uom"];
                        return $value1;
                    },
                    "cssStyle" => "background-color: #b1dfbb;",
                ),
                "periode - periode2 | quantity - sum" => array(
                    "label" => "Quantity<br>" . $periode2,
                    "formatValue" => function ($value, $row) {
                        $value1 = number_format($value, 2, '.', ',') . " " . $row["uom"];
                        return $value1;
                    }
                ),
                "quantityVS" => array(
                    "label" => "Quantity:<br>current vs previous",
                    "formatValue" => function ($value, $row) {
                        return ($value == 'N/A') ? 'new spoiled item' : number_format($value, 1, '.', ',') . "%";
                    },
                    "cssStyle" => "background-color: #D3D3D3;",
                ),
                "periode - periode1 | total - sum" => array(
                    "label" => "Amount<br>" . $periode1,
                    "footer" => "sum",
                    "cssStyle" => "background-color: #b1dfbb;",
                    "formatValue" => function ($value, $row) {
                        $value1 = number_format($value, 0, '.', ',');
                        return $value1;}
                ),
                "periode - periode2 | total - sum" => array(
                    "label" => "Amount<br>" . $periode2,
                    "footer" => "sum",
                    "formatValue" => function ($value, $row) {
                        $value1 = number_format($value, 0, '.', ',');
                        return $value1;}
                ),
                "amountVS" => array(
                    "label" => "Amount:<br>current vs previous",
                    "formatValue" => function ($value, $row) {
                        return ($value == 'N/A') ? 'new spoiled item' : number_format($value, 1, '.', ',') . "%";
                    },
                    "cssStyle" => "background-color: #D3D3D3;",
                ),
                "diff_consum" => array(
                    "label" => "Consumption:<br>current vs previous",
                    "formatValue" => function ($value, $row) {
                        return ($value === 'N/A') ? $value : number_format($value, 1, '.', ',') . "%";
                    },
                    "cssStyle" => "background-color: orange;",
                ),
            ),
            "excludedColumns" => $this->params["excluded"],
//            "grouping" => array(
//                "category" => array(
//                    "top" => "<td <td class='top_group'><b>{category} </b></td>",
//                ),
//            ),
            "cssClass" => array(
                "table" => "table table-hover table-bordered",
                "td" => function ($row, $columnName) {
                    return ($columnName == "name") ? "cell-class-name cell-class-small" : "cell-class cell-class-small";
                },
                "th" => "cell-class",
                "tf" => "footer-class"
            )
        ))
        ?>
    </div>
</body>
</html>

Give tips to supporter for his good work

If you feel that supporter has done a good work, consider giving him some credit. Any amount put into the tips box below is appreciated. By doing so, you have contribtuted to the existence of KoolReport and the quality of support.

Tips box
help needed

CloudExport