PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, February 4, 2022

[FIXED] Cakepdf not showing image for DomPdf

 February 04, 2022     cakephp, cakephp-4.x, dompdf     No comments   

Issue

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


Solution

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

  • https://github.com/FriendsOfCake/CakePdf/tree/4.1.1#configuration
  • https://github.com/dompdf/dompdf/wiki/Usage#options
  • https://github.com/dompdf/dompdf/wiki/Usage#security-restrictions-for-local-files
  • https://github.com/dompdf/dompdf/issues/2229


Answered By - ndm
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing