Search code examples
phpyii2dompdf

PHP Fatal Error – yii\base\ErrorException Class 'Dompdf\FrameDecorator\Page' not found


I am trying to us Dompdf in my yii2 application, but it's showing me an error message.

PHP Fatal Error – yii\base\ErrorException Class
'Dompdf\FrameDecorator\Page' not found

and I don't understand reason of that.


Solution

  • You should run this command to add this extension into your composer.json.

    composer require dompdf/dompdf
    

    OR add this line in your composer.json require section and run composer update:

    "require": {
        "dompdf/dompdf": "^0.7.0"
    },
    

    And then in your view access this way.

    // reference the Dompdf namespace
    use Dompdf\Dompdf;
    
    // instantiate and use the dompdf class
    $dompdf = new Dompdf();
    $dompdf->loadHtml('hello world');
    
    // (Optional) Setup the paper size and orientation
    $dompdf->setPaper('A4', 'landscape');
    
    // Render the HTML as PDF
    $dompdf->render();
    
    // Output the generated PDF to Browser
    $dompdf->stream();