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

#gocubs. I’ll root for them over the Dodgers :)PhotoBig stuff planned here tomorrow night. #alcsIt’s hot in these here parts.Hunting is one of the few activities that necessitates slowing down and becoming keenly aware of your surroundings.Magic hour #nofilterHunting time. #youthhuntWarming up his swing. GO #southsidelittleleague !!My first ever granny square! Why when I tried this years ago could I not figure it out? Probably YouTube tutorials dawned since then! Like a free craft class at 9:30 at night --- hard to beat it:blush:The house is set for next weekend. #youthhunt Mr SmilesHappy birthday facesNo wonder Lucas has been eating like a horse lately... he's growing like a weed!!! #lifewithboys #growthspurt #threeyearoldsarefunDecided to try and remember how to crochet. Top is my first attempt at a square :joy:. Oops!!! #droppingstitches #crochetingisfunHanging out w mom and Julie in the finger lakes for the weekend. Had a fun time at Naples Grape festival. #lifewithgirls #umbrellahatsarecool #naplesgrapefest

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

#gocubs. I’ll root for them over the Dodgers :)PhotoBig stuff planned here tomorrow night. #alcsIt’s hot in these here parts.Hunting is one of the few activities that necessitates slowing down and becoming keenly aware of your surroundings.Magic hour #nofilterHunting time. #youthhuntWarming up his swing. GO #southsidelittleleague !!My first ever granny square! Why when I tried this years ago could I not figure it out? Probably YouTube tutorials dawned since then! Like a free craft class at 9:30 at night --- hard to beat it:blush:The house is set for next weekend. #youthhunt Mr SmilesHappy birthday facesNo wonder Lucas has been eating like a horse lately... he's growing like a weed!!! #lifewithboys #growthspurt #threeyearoldsarefunDecided to try and remember how to crochet. Top is my first attempt at a square :joy:. Oops!!! #droppingstitches #crochetingisfunHanging out w mom and Julie in the finger lakes for the weekend. Had a fun time at Naples Grape festival. #lifewithgirls #umbrellahatsarecool #naplesgrapefest