PDF Output

To create a PDF report on the fly use the method to("PDF") as shown below. Reportico ships with two types of PDF generator, TCPDF and Chromium and depending on your environment you will eed to choose which is best for you.

The tcpdf option is the default and will work on all environments but produces an output which is slightly different from the output shown in the browser.

The chromium pdf engine uses the Chromium browser to render the output which looks exactly as it is in the browser. However in order to use this you will to ensure that Node and the Node package manager is installed and install the necessary puppeteer node package. This option may not be available if you are running Reportico on a hosted system provided by an ISP that does not allow running of custom applications. If your system does allow Node to run or you have control over your system then you can install the Chromium/Puppeteer pdf engine as follows :-

Ensure you have node and npm installed in your system.

In a command shell move to your application folder. If you are using Reportico within a web framework such as Laravel or including Reportico in your web pages this will be your web appplication root folder. Otherwise, if using Reportico in standalone mode its the top level of your Reportico directory.

Ensure you have a package.json file in the necessary structure defined by npm and add puppeteer as a dependency as follows.

    "dependencies": {
        ...
        "puppeteer": "^5.2.1"
    },

Then run npm install which will install the puppeteer pdf engine and download the necessary headless Chromium which it uses.

To set Chromium as the default pdf generator you you can set it as follows :-
  • For standalone Reportico.php edit the start.php and find and set the pdf_engine setting
    $reportico->pdf_engine = "chromium";
  • For Laravel change vendor/reportico/laravel-reportico/src/config.php and find and set
    'pdf_engine' => "chromium"

Download Method



The pdfDownLoadMethod() allows the choice of whether to show the report inline in the browser or download to your local machine either from a new browser window or the current browser window. Pass either inline, newwindow or samewindow.

Click for a Chromium report Click for a TCPDF report.



<?php
          
\Reportico\Engine\Builder::build()
              ...
              ...
              ->
to("PDF")
              ->
pdfEngine("tcpdf" "chromium" )
              ->
pdfDownloadMethod("inline" "samewindow" "newwindow" )
              ->
execute();
?>
1




<?php
      
require_once(__DIR__ .'/../vendor/autoload.php');
      

      \
Reportico\Engine\Builder::build()
          ->
properties([ "bootstrap_preloaded" => true])
          ->
datasource()->database("mysql:host=localhost; dbname=DATABASE NAME")->user("USER")->password("PASSWORD")
          ->
title     ("Product Stock")
          ->
description     ("Produces a list of our products")
          ->
sql       ("
              SELECT  ProductID id, ProductName product, UnitsInStock in_stock, UnitsOnOrder on_order, companyname Company, country, categoryname category
              FROM northwind_products 
              join northwind_suppliers on northwind_products.supplierid = northwind_suppliers.supplierid
              join northwind_categories on northwind_products.categoryid = northwind_categories.categoryid
              WHERE 1 = 1  
              ORDER BY categoryname
                "
)
          ->
group("category")
              ->
header("category")
              ->
throwPageBefore()
          ->
page()
            
//->paginate()
            //->pagetitledisplay("Off")
            
->header("{REPORT_TITLE}""border-width: 0px 0px 1px 0px; margin: 25px 0px 0px 0px; border-color: #000000; font-size: 18; border-style: solid;padding:0px 0px 0px 0px; width: 100%; background-color: inherit; color: #000; margin-left: 0%;margin-bottom: 70px;text-align:center")
            ->
header"""width: 100; height: 50; margin: 5px 0 0 0; background-image:../assets/images/reportico100.png'"  )
            ->
footer'Page: {PAGE} of {PAGETOTAL}''border-width: 1 0 0 0; top: 0px; font-size: 8pt; margin: 2px 0px 0px 0px; font-style: italic; margin-top: 30px;'  )
            ->
footer'Time: date(\'Y-m-d H:i:s\')''font-size: 8pt; text-align: right; font-style: italic; width: 100%; margin-top: 30px;'  )
            ->
pdfengine("chromium")
            ->
to"PDF" )
          ->
execute();
?>