1

I am using cakepdf plugin to generate pdf in cakephp application. I am using below configuration for 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
]);

I have added 'isRemoteEnabled'=> true

For display image I have used

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

I have also tried by

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

Same result no any change found. $this->Html->image this way also not working for WkHtmlToPdf. I am using PHP version 7.4.x

This image perfectly showing if I use WkHtmlToPdf engine, but for dompdf I am not getting image, it's showing not found. Like below image

enter image description here

Niloy Rony
  • 602
  • 1
  • 8
  • 23

1 Answers1

1

Engine options must be passed via the engine option, eg:

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

Also note that the WWW_ROOT constant holds is a filesystem path! In order to be able to access the filesystem you must configure the chroot option in recent versions of Dompdf!

'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,
        ],
    ]
],

See also

ndm
  • 59,784
  • 9
  • 71
  • 110