sim.plified.com

Chris Pollock

Chris Pollock - web developer & ecommerce entrepreneur
undivided… my thoughts on world, family, church, business, technology and Jesus Christ (all in all)

Make DOMPDF work with Magento

I’m currently working on a project where I wanted to use DOMPDF to export html from magento.  With some help from some folks who got DOMPDF to work with Zend I was able to get it working with Magneto.

Step 1

Copy the dompdf folder to the lib directory of your magento install.

Step 2

Edit app/Mage.php to include the following code

include_once 'dompdf/dompdf_config.inc.php';
spl_autoload_register('DOMPDF_autoload');

This goes around line 52 inside the else statement right after

 include_once "Varien/Autoload.php";

Step 3

Use the code.  Here’s an example of what I  am doing inside on of my custom contollers

public function printAction(){
        
        
        if ($quote = $this->_iniQuote()) {
            
            $html = $this->getLayout()->createBlock('crm/quotes_print')->toHtml();
            
            $dompdf = new DOMPDF();
            $dompdf->load_html($html);
            $dompdf->render();
            $dompdf->stream("sample.pdf");
            
         }
        
    }

Basically that’s it.  Pretty straight forward and seems to work like a charm.

NOTE:  This was done using DOMPDF 0.6.0 beta1 and Magneto 1.4.0.1

  • http://excellencetechnologies.in/ manish

    The above doesn't work follow this

    Put this in dompdf_config.inc.php

    $autoload = Varien_Autoload::instance();
    spl_autoload_unregister(array($autoload,'autoload'));

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

    if ( is_file($filename) ){
    require_once($filename);
    }else{
    $autoload = Varien_Autoload::instance();
    $autoload->autoload($class);
    }
    }

  • dgento

    unfortunately, both of the above ideas didn't work. 🙁

  • http://ricardomartins.net.br Ricardo Martins

    You need to keep the instructions on the post and add the Manish instructions.

    You need to replace the DOMPDF_autoload funcion on dompdf file with the Manish one.

    If you dont want to touch on your Mage.php (like I do), you can simply add this at the beginning of your controller file:

    require_once(Mage::getBaseDir('lib') . '/dompdf/dompdf_config.inc.php');
    spl_autoload_register('DOMPDF_autoload');

    And do not touch in the Mage.php. But yes, you will need to change the dompdf_config.inc.php as Manish said.

Things I see

Beautiful summer day in RochesterLicensed to kill...deer that is. And small woodland varmits"Daddy I'm cool" :sunglasses:Mmmm marsh mellows@ladyloki, Look a new one!!! Very english. Almost can't detect the lavender, but very tasty!! I'll get you one for when you visit Rochester if they're still at the store next time I go. #kombucha ##jetlagBackGatwick airport.... how it looks to spend 12 hours there:grimacing:. Kids did an amazing jobs helping cart around ALL our 25+ bags!!! God sent many helpful people along the way. #tryagaintoday #flightcancelled #lifewithboys #25 hours later back in home sweet home. Love is not efficient- both of these guys met me at the airport at 2am!Homeward boundWelcome to the This is our newest addition to the rental property, care of Lucas finding a rock on the floor inside and dutifully trying to throw it out the open door opposite this now shattered pane. Just had the glazier here Friday to get replacement panes for broken Lucas has self captioned this original piece of artwork. He calls it "Broken Glass"! #lifewithboysKids love the rain. Maybe a connection between this and the fact that unless we become like children we will not enter the kingdom of God.Great Britain comes complete with free blackberries!!!! Super sweet. #berrygreatbritain

Chris Pollock

Web Developer - proficient in both PHP and ASP.NET.
Rochester, New York

View my web developement site.

View Chris Pollock's LinkedIn profile

My Pictures

Beautiful summer day in RochesterLicensed to kill...deer that is. And small woodland varmits"Daddy I'm cool" :sunglasses:Mmmm marsh mellows@ladyloki, Look a new one!!! Very english. Almost can't detect the lavender, but very tasty!! I'll get you one for when you visit Rochester if they're still at the store next time I go. #kombucha ##jetlagBackGatwick airport.... how it looks to spend 12 hours there:grimacing:. Kids did an amazing jobs helping cart around ALL our 25+ bags!!! God sent many helpful people along the way. #tryagaintoday #flightcancelled #lifewithboys #25 hours later back in home sweet home. Love is not efficient- both of these guys met me at the airport at 2am!Homeward boundWelcome to the This is our newest addition to the rental property, care of Lucas finding a rock on the floor inside and dutifully trying to throw it out the open door opposite this now shattered pane. Just had the glazier here Friday to get replacement panes for broken Lucas has self captioned this original piece of artwork. He calls it "Broken Glass"! #lifewithboysKids love the rain. Maybe a connection between this and the fact that unless we become like children we will not enter the kingdom of God.Great Britain comes complete with free blackberries!!!! Super sweet. #berrygreatbritain