如何使用 Laravel 和 UTF 创建新的 FCPDF 实例

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

原版有功能

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

但我正在使用为 Laravel (https://packagist.org/packages/elibyy/tcpdf-laravel)

创建的那个

而且几乎没有文档,所以我无从下手。有人知道如何实现吗?

如何将默认 pdf 字符集设置为 pdf?

您的应用程序的 /config/ 文件夹中应该有一个 tcpdf.php 文件,您可以在其中设置一些配置详细信息,如下所示:

<?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,
];

如果您的配置文件不存在,正如 docs 所说,您可以创建它:

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.