KoolReport's Forum

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

Laravel Export to pdf Issue #409

Open Sunil Kumar opened this topic on on Aug 9, 2018 - 2 comments

Sunil Kumar commented on Aug 9, 2018

Hello I'm trying to export pdf, but it returns me blank pdf if there is any Table or chart used inside the view.php file. If i'm trying with simple html then it will output that content in PDF. I have also make use of use \koolreport\export\Exportable; package.

This is my MyReport.view.php file

<?php 
use \koolreport\widgets\google\BarChart;

$category_amount = array(
        array("category"=>"Books","sale"=>32000,"cost"=>20000,"profit"=>12000),
        array("category"=>"Accessories","sale"=>43000,"cost"=>36000,"profit"=>7000),
        array("category"=>"Phones","sale"=>54000,"cost"=>39000,"profit"=>15000),
        array("category"=>"Movies","sale"=>23000,"cost"=>18000,"profit"=>5000),
        array("category"=>"Others","sale"=>12000,"cost"=>6000,"profit"=>6000),
    );
?>

<html>
    <head>
        <title>Content that you want to convert to PDF</title>

    </head>
    <body>
      
    <style>
      
        h1 {color:red}
    </style>

        
        <h1>PDF</h1>
       
       

            <h1>Column chart div</h1>

            <?php
                BarChart::create(array(
                    "title"=>"Sale Report",
                    "dataStore"=>$category_amount,
                    "columns"=>array(
                        "category"=>array("label"=>"category"),
                        "sale"=>array("label"=>"Sale","type"=>"number","prefix"=>"$"),
                        "cost"=>array("label"=>"Cost","type"=>"number","prefix"=>"$"),
                        "profit"=>array("label"=>"Profit","type"=>"number","prefix"=>"$"),
                    )
                ));
            ?>
    <body>
</html>

this is my report.blade.php

<?php echo $report->render();?>

and this is my ReportController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Reports\MyReport;

use View;
use \koolreport\instant\Widget;
use \koolreport\chartjs\ColumnChart;



class ReportController extends Controller{
  
	public function __construct()
    {
        $this->middleware("guest");
    }
  

    public function index(Request $Request){
     $report = new MyReport();
        $report->export()
        ->settings(array(
            "resourceWaiting"=>5000,
        ))
        ->pdf(array(
            "format"=>"A4",
            "orientation"=>"portrait"
        ))
        ->toBrowser("report.pdf");
       

    }
    
}

I got stuck on the problem. Please help. Regards

David Winterburn commented on Aug 10, 2018

Hi Sunil Kumar,

Please try adding the "assets" property to your report's setting like this:

		function settings()
		{
			return array(
				'assets' => array(
					'path' => public_path(),
					'url' => '',
				),
				"dataSources"=>array(
			            ...
                                )
			);
                }

Please let us know if there's still any problem. Thanks!

Sunil Kumar commented on Aug 10, 2018

Hi,

This is my setting function.

public function settings(){
    return array(
        "assets"=>array(
            "path"=> public_path(),
            "url"=>"",
        ),
        "dataSources"=>array(
            "mysql_datasource"=>array(
                "connectionString"=>"mysql:host=localhost;dbname=ipanalysis",
                "username"=>"root",
                "password"=>" ",
                "charset"=>"utf8"
            )
        )
        
    );
}

Still Blank Pdf....... :(

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