KoolReport's Forum

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

Export to pdf: Can't add any css to pdf file and also logo #2593

Open FIMM opened this topic on on Feb 24, 2022 - 1 comments

FIMM commented on Feb 24, 2022

I am using laravel koolreport pro version. Now Export to pdf ok, but I can't add any css or logo.

->pdf(array(

            "format"=>"A4",
            "orientation"=>"portrait",
            //"zoom"=>2,
           // "margin"=>"1in",
            "margin"=>array(
                "top"=>"0.5in",
                "bottom"=>"0.5in",
                "left"=>"1in",
                "right"=>"1in",
            ),
            "header"=>array("height"=>"300px","contents"=>"this is header"),
           "footer"=>array("height"=>"300px","contents"=>"this is footer")
        ))

Here header and footer not working.

Below My full code: CasUtcReport.php <?php namespace App\Reports; class CasUtcReport extends \koolreport\KoolReport {

use \koolreport\laravel\Friendship;
use \koolreport\clients\FontAwesome;
use \koolreport\amazing\Theme;
use \koolreport\export\Exportable;
function setup()
{
    $this->src("mysql")
    ->query("Select CONSULTANT.CONSULTANT_ID AS CONSULTANT_ID,CONSULTANT.CONSULTANT_NAME AS CONSULTANT_NAME,CONSULTANT.CONSULTANT_NRIC AS CONSULTANT_NRIC,CONSULTANT.CONSULTANT_PASSPORT_NO AS CONSULTANT_PASSPORT_NO,CONSULTANT.CONSULTANT_FIMM_NO AS CONSULTANT_FIMM_NO,CONSULTANT.CONSULTANT_FIMM_NO AS CONSULTANT_FIMM_NO,CONSULTANT.CREATE_TIMESTAMP AS START_DATE,SETTING_GENERAL.SET_PARAM AS SET_PARAM,CA_RECORD.CREATE_TIMESTAMP AS UPDATE_DATE,DISTRIBUTOR.DIST_NAME AS DIST_NAME,CONSULTANT_TYPE.TYPE_NAME AS TYPE_NAME  from consultant_management.CONSULTANT AS CONSULTANT JOIN consultantAlert_management.CA_RECORD AS CA_RECORD ON CA_RECORD.CONSULTANT_ID = CONSULTANT.CONSULTANT_ID left join admin_management.SETTING_GENERAL AS SETTING_GENERAL ON SETTING_GENERAL.SETTING_GENERAL_ID = CONSULTANT.CONSULTANT_STATUS left join distributor_management.DISTRIBUTOR AS DISTRIBUTOR ON DISTRIBUTOR.DISTRIBUTOR_ID = CONSULTANT.DISTRIBUTOR_ID left join consultant_management.CONSULTANT_LICENSE AS CONSULTANT_LICENSE ON CONSULTANT_LICENSE.CONSULTANT_ID = CONSULTANT.CONSULTANT_ID left join admin_management.CONSULTANT_TYPE AS CONSULTANT_TYPE ON CONSULTANT_TYPE.CONSULTANT_TYPE_ID = CONSULTANT_LICENSE.CONSULTANT_TYPE_ID where SETTING_GENERAL.SET_TYPE = 'CLASSIFICATION' AND CONSULTANT.CONSULTANT_STATUS IN(263,264,265,266,267,268,269)")
   ->pipe($this->dataStore("CONSULTANTS"));
}

}

CasUtcReportPdf.view.php <?php use \koolreport\datagrid\DataTables; ?> <!DOCTYPE html> <html lang="en"> <head>

<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
    * {
        -webkit-print-color-adjust: exact !important;
    } 

@media print {

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

</style> </head>

<body style="margin:0.5in 1in 0.5in 1in">
<?php
     $logoSrc = url('/')."/assets/logo_report.png";
?>
    <div class="text-left" style="height:30px">
        <span>Header </span>
        <img   width="100" height="100" src="<?php echo $logoSrc; ?>" />
    </div>
    <div class="text-left">
        <h1 style="color:red">Report Name</h1>
        <h4>Report <?php echo date("Y/m/d"); ?></h4>
        <h4>Module Name</h4>
    </div>
    <hr/>
    <?php
     DataTables::create([
        "dataSource"=>$this->dataStore("CONSULTANTS"),
        "showFooter" => "bottom",
        "columns"=>array(
            "CONSULTANT_NAME"=>array(
                "label"=>"NAME",
                "type"=>"string",
                "searchable" => true,
            ),
            "CONSULTANT_NRIC"=>array(
              "label"=>"NRIC NO",
              "type"=>"string",
              "searchable" => true,
            ),
            "CONSULTANT_PASSPORT_NO"=>array(
                "label"=>"PASSPORT NO",
                "type"=>"string",
            ),
            "TYPE_NAME"=>array(
                "label"=>"TYPE OF LICENSE",
                "type"=>"string",
            ),
            "CONSULTANT_FIMM_NO"=>array(
                "label"=>"FIMM NO",
                "type"=>"string",
            ),
            "SET_PARAM"=>array(
                "label"=>"STATUS",
                "type"=>"string",
            ),
            "DIST_NAME"=>array(
                "label"=>"COMPANY",
                "type"=>"string",
            ),
            "START_DATE"=>array(
                "label"=>"START DATE",
                "type"=>"datetime",
                "format"=>"Y-m-d H:i:s",
                "displayFormat"=>"m/d/Y"
            ),
            "UPDATE_DATE"=>array(
                "label"=>"UPDATE/COMPLAINT DATE",
                "type"=>"datetime",
                "format"=>"Y-m-d H:i:s",
                "displayFormat"=>"m/d/Y"
            ),
        ),
        "cssClass"=>array(
            "table"=>"table table-bordered table-striped"
        )
    ]);
    ?>
     <div  style="height:30px">
     <span>Page {pageNum}/{numPages}</span>
    </div>
</body>

</html> DashboardChartTypeControlle.php <?php namespace App\Http\Controllers;

use App\Models\DashboardChartType; use GuzzleHttp\Exception\RequestException; use Illuminate\Http\Request; use Illuminate\Support\Facades\Http; use Ixudra\Curl\Facades\Curl; use Validator; use DB; use Illuminate\Support\Facades\Log; use App\Reports\CasUtcReport;

class DashboardChartTypeController extends Controller { public function getCasUtcTaggingListPdfReport(Request $request)

{
    try{
        \DB::connection()->enableQueryLog();
        $report = new  CasUtcReport;
         $report->run()
        ->export('CasUtcReportPdf')
         ->settings(array(
            "useLocalTempFolder"=>true,
            "autoDeleteLocalTempFile"=>true,
            "phantomjs"=>"/usr/bin/phantomjs",
           // "resourceWaiting"=>2000,
            "serverLocalAddress" => "localhost"
        ))
        ->pdf(array(
            "format"=>"A4",
            "orientation"=>"portrait",
            //"zoom"=>2,
           // "margin"=>"1in",
            "margin"=>array(
                "top"=>"0.5in",
                "bottom"=>"0.5in",
                "left"=>"1in",
                "right"=>"1in",
            ),
            "header"=>array("height"=>"300px","contents"=>"this is header"),
           "footer"=>array("height"=>"300px","contents"=>"this is footer")
        ))
        ->toBrowser("report.pdf",true);
    } catch (RequestException $r) {
        http_response_code(400);
        return response([
        'message' => 'Failed to retrieve data.',
        'errorCode' => 4103
        ],400);
    }
}

} } Please help me.

Thanks

Sebastian Morales commented on Feb 24, 2022

Pls check how to construct pdf export's header and footer here:

https://www.koolreport.com/docs/export/get_started/#export-to-pdf-header-and-footer-of-the-page

If you follow this documentation but the result is not correct let us know. Tks,

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
solved

None