【问题标题】:Cakepdf not showing image for DomPdfCakepdf 不显示 DomPdf 的图像
【发布时间】:2021-09-15 06:05:04
【问题描述】:

我正在使用 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->image 这种方式也不适用于 WkHtmlToPdf。我正在使用 PHP 版本 7.4.x

如果我使用 WkHtmlToPdf 引擎,此图像完美显示,但对于 dompdf,我没有得到图像,它显示未找到。如下图所示

【问题讨论】:

    标签: cakephp dompdf cakephp-4.x


    【解决方案1】:

    引擎选项必须通过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,
            ],
        ]
    ],
    

    另见

    【讨论】:

      猜你喜欢
      • 2021-12-17
      • 2017-03-30
      • 2018-01-24
      • 2011-05-18
      • 2020-02-03
      • 2013-05-28
      • 1970-01-01
      • 2013-02-15
      • 1970-01-01
      相关资源
      最近更新 更多