CakePHP and dompdf autoload error

I recently tried using dompdf in a CakePHP project to easily generate PDFs from HTML. I ran into a rather obtuse error while trying to render a page and generate a PDF in the same controller action.

Fatal error: require_once() [function.require]: Failed opening required 'vendors/dompdf/include/htmlhelper.cls.php' in vendors/dompdf/ on line 194

That makes it seem a lot like dompdf is trying to include one of its files and failing. What’s really happening is dompdf is specifying an __autoload function which PHP is attempting to use to load the HtmlHelper class used by CakePHP. dompdf blindly includes the file if it exists or not thinking only its files would be loaded this way. To get around this and load the files normally, simply edit the DOMPDF_autoload function to make sure the file exists before including.

function DOMPDF_autoload($class) {
    $filename = DOMPDF_INC_DIR . "/" . mb_strtolower($class) . ".cls.php";
    if(is_file($filename)) {

I found this snippet after much searching over at, hopefully this post will save someone else a few minutes of googling.

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *