# Introduction

This package utilizes the MPDF library to generate pdf from a report's rendered html. Notable features include html and css support, paging, header and footer, barcode, table of contents, bookmark, watermark, etc.

Remember that MPDF generates PDF directly and doesn't use browser rendering like WkHtmlToPdf, PhantomJS or Headless Chrome so don't expect it to execute javascript in your html before converting it to PDF.

# Installation

1. Download the `printpdf` package and unzip it.
2. Copy the folder `printpdf` into folder `koolreport`.
3. Open printpdf folder in your command line and run: composer install
4. Include `koolreport/core/autoload.php` in your report.

All done! Enjoy exporting your report with KoolReport now.

# Documentation

## Usage

To enable printpdf's export feature in KoolReport, you do:

```
//MyReport.php
class MyReport extends \koolreport\KoolReport
{
    use \koolreport\printpdf\Exportable;
    ...
}
```

Now your MyReport has ability to export, you do:

```
//export.php
...
$report = new MyReport();
$report->run()
->printPDF('MyReportPDF')
->pdf(array(
    ...
))
->toBrowser("MyReport.pdf");

//MyReportPDF.view.php
<html>
    <head>
    ...
    </head>
    <body>
    ...
    </body>
</html>
```

## Paging and page numbering

You could force a page break by using \<pagebreak\> tag inside your html:

```
//MyReportPDF.view.php
...

<pagebreak />
...

```
Page number could be reset to 1 after each page break by using attribute "resetpagenum" in \<pagebreak\> tag:
```
//MyReportPDF.view.php
...

<pagebreak resetpagenum="1" />
...

```
Various other options are also documented at [MPDF pagebreak](https://mpdf.github.io/reference/html-control-tags/pagebreak.html).

## Headers and footers

You could define and use multiple headers and users in a report view's html. Headers' and footers' definition must happen at the beginning of the \<body\> tag. Headers' and footers' uses affect to the start of the report or the nearest previous page break. For example:
```
<html>
    <head>
        <!-- css links -->
    </head>
    <body>
        <!-- headers' and footers' definition -->
        <defheader name="my1stheader">
            <span>My report header {date}</span>
        </defheader>
        <defheader name="my2ndheader">
            <span>Page {pageNum}/{pageGroupTotal}/{pageTotal}</span>
        </defheader>

        <deffooter name="myfooter">
            <div>My report footer {date}</div>
        </deffooter>

        <header name="my1stheader" />
        <footer name="myfooter" />
        <!-- report html -->

        <pagebreak />
        <header name="my2ndheader" />
        <!-- report html -->
    </body>
</html>
```
Placeholders that could be used in headers and footers are {date}, {pageNum}, {pageGroupTotal} and {pageTotal}.
Date could be customized by adding a PHP format string inside date placeholder. For example: {date d/m/Y}, {date j-m-Y H:m}, etc.

There's a special type of header by the tag \<firstheader\> which only appears in the first page of a report or right after a page break:
```
<html>
    <body>
        <defheader name="firstpage">
            ...
        </defheader>

        <defheader name="otherpages">
            ...
        </defheader>

        <firstheader name="firstpage" />
        <header name="otherpages" />
        ...

        <pagebreak />
        <firstheader name="firstpage" />
        <header name="otherpages" />
        ...
    </body>
</html>
```
Some other options of headers' and footers' definition and use are also documented at [MPDF headers](https://mpdf.github.io/reference/html-control-tags/sethtmlpageheader.html) and [MPDF footers](https://mpdf.github.io/reference/html-control-tags/sethtmlpageheader.html)

# Credit

We thank the MPDF's team for creating and maintaining an awesome software. For further information please visit their [project](https://github.com/mpdf/mpdf).

# Support

Please use [our forum](https://www.koolreport.com/forum/topics) if you need support. By this way other people can benefit as well. If the support request needs privacy, you may send email to us at __support@koolreport.com__.