Search code examples
cakephpdompdf

How to implement dompdf in cakephp 3?


I just making website that can make html file into pdf using cakephp 3 as php framework.

this is my code in layout as default.ctp for pdf view that i want to convert

<?php  
require_once(APP . 'Vendor' . DS . 'dompdf' . DS . 'dompdf_config.inc.php'); 
spl_autoload_register('DOMPDF_autoload'); 
$dompdf = new DOMPDF(); 
$dompdf->set_paper = 'A4';
$dompdf->load_html(utf8_decode($content_for_layout), Configure::read('App.encoding'));
$dompdf->render();
echo $dompdf->output();

when i try to run it, it some error like this

Error: Class 'Configure' not found 
File C:\xampp\htdocs\MyProject\src\Template\Layout\pdf\default.ctp 
Line: 6

is my syntax for calling dompdf is not right?


Solution

  • It is not dompdf error.
    It is because of this Configure::read('App.encoding').

    Write this on top of your file and your code should work.
    use Cake\Core\Configure;