Search code examples
phplaravelpdffpdf

How do I create a new FCPDF instance using Laravel with UTF


In original one there's functionality

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

But I am using that one created for Laravel (https://packagist.org/packages/elibyy/tcpdf-laravel)

And there is nearly no docs so I have no way of doing it. Does anyone have any idea how to achieve it?

How can i set default pdf charset to pdf?


Solution

  • You should have a tcpdf.php file on your /config/ folder in your app, there you can set some configuration details like this:

    <?php
    return [
        'page_format'           => 'A4',
        'page_orientation'      => 'P',
        'page_units'            => 'mm',
        'unicode'               => true,
        'encoding'              => 'UTF-8', // <- Your desired encoding <-
        'font_directory'        => '',
        'image_directory'       => '',
        'tcpdf_throw_exception' => false,
    ];
    

    In case your configuration file don't exists, as the docs says you can create it doing:

    Laravel-TCPDF comes with some basic configuration. If you want to override the defaults, you can publish the config, like so:

    php artisan vendor:publish
    

    Now access config/tcpdf.php to customize.