DOMPDF with Zend Framework 1.9.x

If you’re getting these sort of errors when trying to use DOMPDF in Zend Framework 1.9.x …

Warning: include(DOMPDF.php) [function.include]: failed to open stream: No such file or directory in /home/myusername/library/Zend/Loader.php on line 83
Warning: include(DOMPDF.php) [function.include]: failed to open stream: No such file or directory in /home/myusername/library/Zend/Loader.php on line 83
Warning: include() [function.include]: Failed opening 'DOMPDF.php' for inclusion (include_path='/home/myusername/application/models:/home/myusername/library:.:/usr/lib/php:/usr/local/lib/php') in /home/myusername/library/Zend/Loader.php on line 83

And you’ve already tried the solution which has been written about a gajillion times:

require_once('dompdf/dompdf_config.inc.php');
spl_autoload_register('DOMPDF_autoload');
$dompdf = new DOMPDF();

Then I suggest you use the Zend_Loader_Autoloader::pushAutoloader() function, it’s really simple to use in the case of DOMPDF,

First we get the autoloader instance, then we push a new autoloader onto the stack giving the callback function as the first parameter and the namespace as the second. In the case of dompdf there is no namespace so just set it to an empty string.

Like so:

require_once('dompdf/dompdf_config.inc.php');
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->pushAutoloader('DOMPDF_autoload', '');

Note that we have to include the dompdf config file so the autoloader knows about the dompdf autoload function.

3 thoughts on “DOMPDF with Zend Framework 1.9.x

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">