PDF Export
Product Name | Product Vendor | Quantity In Stock | Buy Price |
---|---|---|---|
1969 Harley Davidson Ultimate Chopper | Min Lin Diecast | 7,933 | $48.81 |
1952 Alpine Renault 1300 | Classic Metal Creations | 7,305 | $98.58 |
1996 Moto Guzzi 1100i | Highway 66 Mini Classics | 6,625 | $68.99 |
2003 Harley-Davidson Eagle Drag Bike | Red Start Diecast | 5,582 | $91.02 |
1972 Alfa Romeo GTA | Motor City Art Classics | 3,252 | $85.68 |
1962 LanciaA Delta 16V | Second Gear Diecast | 6,791 | $103.42 |
1968 Ford Mustang | Autoart Studio Design | 68 | $95.34 |
2001 Ferrari Enzo | Second Gear Diecast | 3,619 | $95.59 |
1958 Setra Bus | Welly Diecast Productions | 1,579 | $77.90 |
2002 Suzuki XREO | Unimax Art Galleries | 9,997 | $66.27 |
This example shows you how to export your widget to PDF. Above is a table listing hundred of products. By clicking to [Export to PDF] button, you will have choices to export the current page of table or the whole table to PDF format.
<?php
namespace demo\pdf;
use \koolreport\dashboard\Dashboard;
use \koolreport\dashboard\containers\Row;
use \koolreport\dashboard\containers\Panel;
use \koolreport\dashboard\inputs\Dropdown;
use \koolreport\dashboard\menu\MenuItem;
use \koolreport\dashboard\Client;
use \koolreport\dashboard\containers\Html;
class PDFBoard extends Dashboard
{
protected function onInit()
{
$this->pdfExportable(true); //Turn on pdf exportable for dashboard
}
protected function content()
{
return [
Panel::create()->header("PDF Export")->type("danger")->sub([
Dropdown::create("exportOptions")
->title("<i class='far fa-file-pdf'></i> Export to PDF")
->items([
"Dashboard" => MenuItem::create()
->onClick(
Client::showLoader() .
Client::dashboard($this)->exportToPDF("PDFBoard")
),
"Table's Current Page" => MenuItem::create()
->onClick(
Client::showLoader() .
Client::widget("ProductTable")->exportToPDF("Products - Current Page", ["all" => false])
),
"Table's All Pages" => MenuItem::create()
->onClick(
Client::showLoader() .
Client::widget("ProductTable")->exportToPDF("All Products", ["all" => true])
),
])
->align("right")
->cssStyle("margin-bottom:5px;")
->cssClass("text-right"),
ProductTable::create()
->pdfExportable(true)
]),
\demo\CodeDemo::create("
This example shows you how to export your widget to PDF. Above is a table listing hundred of products.
By clicking to [Export to PDF] button, you will have choices to export the current page of table or
the whole table to PDF format.
")->raw(true)
];
}
}
<?php
namespace demo\pdf;
use \koolreport\dashboard\widgets\Table;
use \demo\AutoMaker;
use \koolreport\dashboard\fields\Text;
use \koolreport\dashboard\fields\Number;
use \koolreport\dashboard\fields\Currency;
use \koolreport\dashboard\containers\Html;
class ProductTable extends Table
{
protected function onInit()
{
$this
->pageSize(10)
// ->pdfExportable(true)
; //Turn on pdf exportable for table
}
protected function onExporting($params)
{
if($params["all"]===true) {
$this->pageSize(null);
}
return true;
}
public function exportedView()
{
return Html::div([
Html::h1("Product List")
])->class("text-center")->view().
$this->view();
}
protected function excelSetting()
{
return [
"showFooter" => true,
"excelStyle" => [
// ...
]
];
}
protected function dataSource()
{
return AutoMaker::table("products")
->select("productName","productVendor","quantityInStock","buyPrice");
}
protected function fields()
{
return [
Text::create("productName"),
Text::create("productVendor"),
Number::create("quantityInStock"),
Currency::create("buyPrice")->USD()->symbol()
];
}
}
<div>
<div>Chart Data Excel Export</div>
<div>
<?php
$styleArray = [
'font' => [
'name' => 'Calibri', //'Verdana', 'Arial'
'size' => 30,
'bold' => true,
'italic' => true,
'underline' => 'none', //'double', 'doubleAccounting', 'single', 'singleAccounting'
'strikethrough' => FALSE,
'superscript' => false,
'subscript' => false,
'color' => [
'rgb' => '808080',
'argb' => 'FF000000',
]
],
];
// echo get_class($report);
// echo get_class($widget);
// $widget->renderXLSXWidget();
// \koolreport\excel\LineChart::create([
\koolreport\excel\Table::create([
"dataSource" => $widget->exportedData(),
"excelStyle" => [
"header" => function ($colName) use ($styleArray) {
return $styleArray;
},
"cell" => function ($colName, $value, $row) use ($styleArray) {
return $styleArray;
},
],
'layout' => null, // false
]);
?>
</div>
<div>
<?php
// echo get_class($widget);
?>
</div>
</div>
<!DOCTYPE html>
<html>
<head></head>
<body>
ProductTable PDF view
<?php echo $widget->pageSize(50)->exportedView(); ?>
</body>
</html>