cakephp Cakepdf未显示DomPdf的图像

jmo0nnb3  于 2022-11-11  发布在  PHP
关注(0)|答案(1)|浏览(127)

我正在使用cakepdf插件在cakephp应用程序中生成pdf。我正在使用下面的配置为dompdf

Configure::write('CakePdf', [
            // 'engine' => 'CakePdf.WkHtmlToPdf',
            'engine' => 'CakePdf.DomPdf',
            'margin' => [
                'bottom' => 15,
                'left' => 50,
                'right' => 30,
                'top' => 45
            ],
            'orientation' => 'landscape',
            'download' => false,
            'isRemoteEnabled'=> true
            // 'enable-local-file-access' => true
]);

我已经添加了'isRemoteEnabled'=> true
用于显示我已使用的图像

<img src="<?= WWW_ROOT ?>img/4dx/01/00.png" />

我也试过

<?php echo $this->Html->image('4dx/01/00.png', ['fullBase' => true]); ?>

同样的结果没有任何变化发现。$this-〉Html-〉图像这种方式也不工作的WkHtmlToPdf。我使用的PHP版本7.4.x
这张图片完美地显示了如果我使用WkHtmlToPdf引擎,但对于dompdf我没有得到图像,它显示没有找到。

7hiiyaii

7hiiyaii1#

引擎选项必须通过engine选项传递,例如:

'engine' => [
    'className' => 'CakePdf.DomPdf',
    'options' => [
        'isRemoteEnabled' => true,
    ]
],

还要注意的是,WWW_ROOT常量是一个文件系统路径!为了能够访问文件系统,您必须在最新版本的Dompdf中配置chroot选项!

'engine' => [
    'className' => 'CakePdf.DomPdf',
    'options' => [
        // allow local file access to webroot and Dompdf files
        'chroot' => [
            WWW_ROOT,
            ROOT . DS . 'vendor' . DS . 'dompdf' . DS . 'dompdf' . DS,
        ],
    ]
],

另请参阅

*http://github.com/FriendsOfCake/CakePdf/tree/4.1.1#configuration
*http://github.com/dompdf/dompdf/wiki/Usage#options
*http://github.com/dompdf/dompdf/wiki/Usage#security-restrictions-for-local-files


相关问题