Skip to content

PdfExporterType

The PdfExporterType represents an exporter that uses a PhpSpreadsheet PDF writer.

Note

Please note that PDF file format has some limits regarding styling cells, number formatting, etc.
For more details, see PhpSpreadsheet PDF Writer documentation.

Options

library

type: string allowed values: 'dompdf', 'mpdf' or 'tcpdf'

PhpSpreadsheet’s PDF Writer is a wrapper for a 3rd-Party PDF Rendering library such as TCPDF, mPDF or Dompdf. You must now install a PDF rendering library yourself; but PhpSpreadsheet will work with a number of different libraries.

Currently, the following libraries are supported:

Library Downloadable from Option value
Dompdf https://github.com/dompdf/dompdf dompdf
mPDF https://github.com/mpdf/mpdf mpdf
TCPDF https://github.com/tecnickcom/tcpdf tcpdf

The different libraries have different strengths and weaknesses. Some generate better formatted output than others, some are faster or use less memory than others, while some generate smaller .pdf files. It is the developers choice which one they wish to use, appropriate to their own circumstances.

orientation

type: string default: 'default' allowed values: 'default', 'landscape' or 'portrait'

PhpSpreadsheet will attempt to honor the orientation and paper size specified in the worksheet for each page it prints, if the renderer supports that. However, you can set all pages to have the same orientation and paper size, e.g.

use Kreyu\Bundle\DataTableBundle\Bridge\PhpSpreadsheet\Exporter\Type\PdfExporterType;
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;

$builder
    ->addExporter('pdf', PdfExporterType::class, [
        'orientation' => PageSetup::ORIENTATION_LANDSCAPE,
    ])
;

Inherited options

sheet_index

type: null or int default: 0

HTML files can only contain one or more worksheets. Therefore, you can specify which sheet to write to HTML. If you want to write all sheets into a single HTML file, set this option to null.

images_root

type: string default: ''

There might be situations where you want to explicitly set the included images root. For example, instead of:

<img src="./images/logo.jpg">

You might want to see:

<img src="https://www.domain.com/images/logo.jpg">

Use this option to achieve this result:

use Kreyu\Bundle\DataTableBundle\Bridge\PhpSpreadsheet\Exporter\Type\HtmlExporterType;

$builder
    ->addExporter('html', HtmlExporterType::class, [
        'images_root' => 'https://www.domain.com',
    ])
;

embed_images

type: bool default: false

Determines whether the images should be embedded or not.

use_inline_css

type: bool default: false

Determines whether the inline css should be used or not.

generate_sheet_navigation_block

type: bool default: true

Determines whether the sheet navigation block should be generated or not.

edit_html_callback

type: null or callable default: null

Accepts a callback function to edit the generated html before saving. For example, you could change the gridlines from a thin solid black line:

use Kreyu\Bundle\DataTableBundle\Bridge\PhpSpreadsheet\Exporter\Type\HtmlExporterType;

$builder
    ->addExporter('html', HtmlExporterType::class, [
        'edit_html_callback' => function (string $html): string {
            return str_replace(
                '{border: 1px solid black;}',
                '{border: 2px dashed red;}',
                $html,
            );
        } 
    ])
;

decimal_separator

type: string default: depends on the server's locale setting

If the worksheet you are exporting contains numbers with decimal separators, then you should think about what characters you want to use for those before doing the export.

By default, PhpSpreadsheet looks up in the server's locale settings to decide what character to use. But to avoid problems it is recommended to set the character explicitly.

thousands_separator

type: string default: depends on the server's locale setting

If the worksheet you are exporting contains numbers with thousands separators, then you should think about what characters you want to use for those before doing the export.

By default, PhpSpreadsheet looks up in the server's locale settings to decide what character to use. But to avoid problems it is recommended to set the character explicitly.

pre_calculate_formulas

type: bool default: true

By default, the PhpSpreadsheet writers pre-calculates all formulas in the spreadsheet. This can be slow on large spreadsheets, and maybe even unwanted. Value of this option determines whether the formula pre-calculation is enabled.

use_headers

type: bool default: true

If this value is true, the output will contain data table headers.

label

type: string default: []

Sets the label that will be used when rendering the exporter to the user. This is used in the export form, where user can select desired exporter (e.g. "CSV" or "XLSX").

label_translation_domain

type: false or string default: the default KreyuDataTable is used

Sets the translation domain used when translating the exporter label.
Setting the option to false disables translation.

tempnam_dir

type: string default: /tmp

Sets the directory, that the temporarily created export files will be saved to. Internally, this value is passed as the first argument to the tempnam() function.

tempnam_prefix

type: string default: exporter_

Sets the prefix of the temporarily created export files. Internally, this value is passed as the second argument to the tempnam() function.