Cloud Export To PDF

This examples show how add page-break to PDF Export

CustomerQ 1
Gift Depot Inc.
Gift Depot Inc. 0.00
La Corne D'abondance, Co.
La Corne D'abondance, Co. 0.00
Mini Caravy
Mini Caravy 0.00
Super Scale Inc.
Super Scale Inc. 0.00
Tekni Collectables Inc.
Tekni Collectables Inc. 2,392.89
Customer Total Q 1 Q 2 Q 3 Q 4 H 1 H 2
Gift Depot Inc. 3,816.99 0.00 4,149.74 0.00 3,109.89 4,150 3,110
La Corne D'abondance, Co. 3,763.20 0.00 3,338.31 1,960.80 4,267.47 3,338 6,228
Mini Caravy 3,992.60 0.00 3,992.60 0.00 0.00 3,993 0
Super Scale Inc. 4,139.92 0.00 3,582.16 0.00 4,767.40 3,582 4,767
Tekni Collectables Inc. 3,895.55 2,392.89 4,145.99 0.00 0.00 6,539 0

The example demonstrate how to add page break in PDF generation. The example requires token key to run and you can follow this instruction in below link to get token key:

Get ChromeHeadless.io Token Key.

Enjoy!

<?php
require_once "MyReport.php";

$report = new MyReport;
$report->run()->render();
<?php
//Step 1: Load KoolReport
require_once "../../../load.koolreport.php";

use \koolreport\processes\ColumnMeta;
use \koolreport\processes\Limit;
use \koolreport\processes\Sort;
use \koolreport\processes\RemoveColumn;
use \koolreport\processes\OnlyColumn;
use \koolreport\processes\Map;
use \koolreport\cube\processes\Cube;
use \koolreport\core\Utility as Util;

//Step 2: Creating Report class
class MyReport extends \koolreport\KoolReport
{
	// use \koolreport\clients\Bootstrap;
	use \koolreport\cloudexport\Exportable;
	
    public function settings()
    {
        //Get default connection from config.php
        $config = include "../../../config.php";

        return array(
            "dataSources"=>$config
        );
    }   
    protected function setup()
    {
        $node = $this->src('salesCSV')
        
        ->pipe(new Map(array(
            '{value}' => function($row, $metaData) {
                $row['orderQuarter'] = 'Q ' . $row['orderQuarter'];
                return array($row);
            },
            '{meta}' => function($metaData) {
                $metaData['columns']['dollar_sales'] = array(
                    'type' => 'number',
                    // "prefix" => "$",
                    "decPoint" => ".",
                    "thoudsandSeparator" => ",",
                    "decimals" => 2,
                );
                $metaData['columns']['orderQuarter'] = array(
                    'type' => 'string',
                );
                return $metaData;
            },
        )))
        ;

        $node->pipe(new Cube(array(
            "rows" => "customerName",
            "column" => "orderQuarter",
            "sum" => "dollar_sales",
            "avg" => "dollar_sales",
            // "sum percent" => "dollar_sales",
            // 'debug' => true,
        )))
        

        ->pipe(new Map(array(
            '{value}' => function($row, $meta) {
                $row['H 1'] = Util::get($row, 'Q 1', 0) + Util::get($row, 'Q 2', 0);
                $row['H 2'] = Util::get($row, 'Q 3', 0) + Util::get($row, 'Q 4', 0);
                return $row;
            },
            '{meta}' => function($meta) {
                $cMetas = & $meta['columns'];
                $cMetas['Q 1']['type'] = 'number';
                $cMetas['Q 1']['decimals'] = 2;
                return $meta;
            }
        )))
        ->pipe(new Sort(array(
            '{{all}}' => 'desc'
        )))
        ->pipe(new Limit(array(
            5, 0
        )))
        ->pipe(new ColumnMeta(array(
            "{{all}}"=>array(
                "label"=>"Total",
            ),
            "customerName"=>array(
                "label"=>"Customer",
            ),
        )))
        ->saveTo($node2);
        
        $node2->pipe($this->dataStore('salesQuarterCustomer'));

        
        
        $node2->pipe(new RemoveColumn(array(
            "{{all}}", 'H 1', 'H 2'
        )))
        ->pipe(new Map([
            '{value}' => function($row) {
                foreach ($row as $k => $v)
                    if ($v == 0)
                        $row[$k] = null;
                return $row;
            }

        ]))
        ->pipe($this->dataStore('salesQuarterCustomerNoAll'));
        
        $node2->pipe(new OnlyColumn(array(
            'customerName', "{{all}}"
        )))->pipe($this->dataStore('salesQuarterCustomerAll'));


    } 

}
<?php
require_once "MyReport.php";
$report = new MyReport;
$report->run();
/**
 * Follow the instruction here to get token key
 * https://www.koolreport.com/docs/cloudexport/chromeheadlessio/#get-token-key 
 */
$secretToken = 'my_cloud_export_secret_token';
$type=isset($_GET['type']) ? $_GET['type'] : 'PDF';
$settings = [
	// 'useLocalTempFolder' => true,
	"pageWaiting" => "networkidle2", //load, domcontentloaded, networkidle0, networkidle2
];
if ($type === 'cloudJPG') {
    $report->cloudExport("MyReportPDF")
    ->chromeHeadlessio($secretToken)
	->settings($settings)
    ->jpg(array(
        // "format"=>"A4",
        // "fullPage" => false
    ))
    ->toBrowser("MyReport.jpg")
    ;
} else if ($type === 'cloudPDF') {
    $pdfOptions = [
        "format"=>"A4",
        'landscape'=>false,
        // 'displayHeaderFooter' => true,
        // 'headerTemplate' => '
            // <div id="header-template" 
                // style="font-size:10px !important; color:#808080; padding-left:10px">
                // <span>Footer command: </span>
                // <span class="date"></span>
                // <span class="title"></span>
                // <span class="url"></span>
                // <span class="pageNumber"></span>
                // <span class="totalPages"></span>
            // </div>
        // ',
        // 'footerTemplate' => '
            // <div id="footer-template" 
                // style="font-size:10px !important; color:#808080; padding-left:10px">
                // <span>Footer command: </span>
                // <span class="date"></span>
                // <span class="title"></span>
                // <span class="url"></span>
                // <span class="pageNumber"></span>
                // <span class="totalPages"></span>
            // </div>
        // ',
        // 'margin' => [
            // 'top'    => '100px',
            // 'bottom' => '200px',
            // 'right'  => '30px',
            // 'left'   => '30px'
        // ],
        // "noRepeatTableHeader" => true,
        "noRepeatTableFooter" => true,
    ];
    $report->cloudExport("MyReportPDF")
    ->chromeHeadlessio($secretToken)
    ->settings($settings)
    ->pdf($pdfOptions)
    ->toBrowser("MyReport.pdf")
    ;
} 
<?php
use \koolreport\datagrid\DataTables;
use \koolreport\morris_chart;
use \koolreport\sparklines;
use \koolreport\widgets\google;
use \koolreport\widgets\koolphp\Table;
use \koolreport\core\Utility as Util;
?>
<form method="post">
	<div class="report-content">
		<div class="text-center" style="margin-bottom:30px;">
			<h1>Cloud Export To PDF</h1>
			<p class="lead">
				This examples show how add <code>page-break</code> to PDF Export
			</p>
			<button type="submit" class="btn btn-primary" formaction="export.php?type=cloudPDF">
				Cloud PDF</button>
			<button type="submit" class="btn btn-primary" formaction="export.php?type=cloudJPG">
				Cloud JPG</button>
		</div>

		<?php 
		  Table::create(array(
			"name" => 'table1',
			"dataStore" => $this->dataStore('salesQuarterCustomer'),
			"columns" => [
			  'customerName',
			  'Q 1'
			],
			"grouping" => [
				  "customerName" => [
					  "top" => "{customerName}",
				]
			  ],
		  ));
		?>

		<table id='tempTable' style='display:none'>
			<tr class='break-row'>
				<td colspan='999'>
				    <div></div><div class='break-before'></div>
				</td>
			</tr>
		</table>
          <script>
            KoolReport.load.onDone(function() {
              var breakRow = document.querySelector('#tempTable tr');
              var tbody = document.querySelector('#table1 tbody');
              var rows = document.querySelectorAll('#table1 tr.row-group');
              for (var i=1; i<rows.length; i+=1) {
                tbody.insertBefore(breakRow.cloneNode(true), rows[i]);
              }
            });
          </script>
		<?php
		$ds = $this->dataStore('salesQuarterCustomer');
		DataTables::create(array(
			'name' => 'salesQuarterCustomer',
			// "dataSource" => $data, 
			"dataSource" => $ds,
			// "columns" => ['customerName'],
			"options" => array(
				"searching" => true,
				"paging" => true,
				"colReorder" => true,
				// "ordering" => false,
				"order" => [],
				// "order" => [[0, 'desc']],
				// 'columnDefs' => array(
				//     array(
				//         'type' => 'customType',
				//         'targets' => 0, //target the first column
				//     )
				// )
			),
			// "columns"=>array(
			//     "customerName" => array(
			//         "label" => "Customer",
			//     ),
			//     "Q 1" => array(
			//         "footer" => "sum",
			//         "footerText"=>"<b>Total: @value</b>",
			//     )
			// ),
			"showFooter" => true,
			// "paging" => array(
			//   "pageSize" => 2
			// )
			"searchOnEnter" => true,
			"searchMode" => "OR",
		));
		
		google\LineChart::create(array(
			"dataStore" => $this->dataStore('salesQuarterCustomerNoAll'),
			"options" => array(
				'title' => 'Top 5 Customers\' Quarterly Sales',
				'isStacked' => true,
				// 'legend' => 'none',
				'pointShape' => 'circle',
				'pointSize' => 10,
				'hAxis' => [
					// 'textPosition' => 'none',
					'showTextEvery' => 4
				],
				'interpolateNulls' => true,
			),
			// 'columns' => array('customerName', 'Q 1'),
			"width" => '100%',
			// 'height'=>'400px',
		));
		
		google\PieChart::create(array(
			"dataStore" => $this->dataStore('salesQuarterCustomerAll'),
			"options" => array(
				'title' => 'Top 5 Customers\' Yearly Sales',
				// 'legend' => 'bottom',
				// 'is3D' => true,
				'chartArea' => array(
					// 'height' => '90%'
					
				),
				
			),
			"width" => '100%',
			// 'height'=>'600px',
		));
		?>
	</div>
</form>
<?php
    use \koolreport\widgets\google;
    use \koolreport\widgets\koolphp\Table;
    // use \koolreport\datagrid\DataTables;
?>
<link rel="stylesheet" type="text/css" href="../../../assets/bs3/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="../../../assets/bs3/bootstrap-theme.min.css">
<style>
    @media  print {
      #table1 .break-row td {
        padding: 0 !important;
      }
    }
</style>
<html>
  <body style='margin: 1in'>
		<?php 
		  Table::create(array(
			"name" => 'table1',
			"dataStore" => $this->dataStore('salesQuarterCustomer'),
			"columns" => [
			  'customerName',
			  'Q 1'
			],
			"grouping" => [
				  "customerName" => [
					  "top" => "{customerName}",
				]
			  ],
		  ));
		?>

		<table id='tempTable' style='display:none'>
			<tr class='break-row'>
				<td colspan='999'>
				    <div></div><div class='break-before'></div>
				</td>
			</tr>
		</table>
          <script>
            KoolReport.load.onDone(function() {
              var breakRow = document.querySelector('#tempTable tr');
              var tbody = document.querySelector('#table1 tbody');
              var rows = document.querySelectorAll('#table1 tr.row-group');
              for (var i=1; i<rows.length; i+=1) {
                tbody.insertBefore(breakRow.cloneNode(true), rows[i]);
              }
            });
          </script>
			<div class='break-before'></div>
            <?php 
				
				google\BarChart::create(array(
					"dataStore"=>$this->dataStore('salesQuarterCustomerNoAll'),
					"options"=>array(
					  'title' => 'Top 5 Customers\' Quarterly Sales',
					  'isStacked' => true
					),
					"width"=>'100%',
					// 'height'=>'400px',
				));
				google\PieChart::create(array(
					"dataStore"=>$this->dataStore('salesQuarterCustomerAll'),
					"options"=>array(
					  'title' => 'Top 5 Customers\' Yearly Sales',
					  // 'legend' => 'bottom',
					  // 'is3D' => true,
					),
					"width"=>'100%',
					// 'height'=>'300px',
				));
            ?>
  </body>
</html>

What People Are Saying

"KoolReport helps me very much in creating data report for my corporate! Keep up your good work!"
-- Alain Melsens

"The first use of your product. I was impressed by its easiness and powerfulness. This product is a great and amazing."
-- Dr. Lew Choy Onn

"Fantastic framework for reporting!"
-- Greg Schneider

Download KoolReport Get KoolReport Pro