Dompdf with CakePHP 3 "Requested HTML document contains no data."

688 views
Skip to first unread message

Ken Lee

unread,
May 8, 2015, 10:12:46 AM5/8/15
to dom...@googlegroups.com
Dear all,

I got dompdf working on CakePHP 2 without problems, following guidelines from pages like http://deliciouscakephp.com/how-to-generate-pdf-in-cakephp-2-x-with-dompdf/

I tried dompdf on CakePHP 3. (I found no pages about dompdf on CakePHP 3). I got my custom layout include "dompdf_config.inc.php" as below:
<?php
        require_once(ROOT . DS . 'vendor' . DS . 'dompdf' . DS . 'dompdf_config.inc.php');
        spl_autoload_register('DOMPDF_autoload');
        $dompdf = new DOMPDF();
        $dompdf->set_paper = 'A4';
        $dompdf->load_html($content_for_layout, 'utf-8');
        $dompdf->render();
        echo $dompdf->output();

Then I get this(screen capture):

Would you advise?

BrianS

unread,
May 8, 2015, 2:04:14 PM5/8/15
to dom...@googlegroups.com, ahke...@gmail.com
Typically you will see this when the content passed to dompdf is null/unset. It looks like in CakePHP 3 you access the content of the document by calling $this->fetch('content') instead of $content_for_layout. So your layout should be something along the lines of:

<?php
require_once
(ROOT . DS . 'vendor' . DS . 'dompdf' . DS . 'dompdf_config.inc.php');
spl_autoload_register
('DOMPDF_autoload');
$dompdf
= new DOMPDF();
$dompdf
->set_paper = 'A4';
$dompdf
->load_html($content_for_layout, 'utf-8');
$dompdf
->render();
echo $dompdf
->output();
?>



No guarantees that this will work. There may be other things you need to account for in the transition from CakePHP 2.x to CakePHP 3.x. For example, you might want to call $dompdf->stream() instead of echo $dompdf->output().
Reply all
Reply to author
Forward
0 new messages