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

Quote form @amylpollock "Children are always the most creative when they are supposed to be doing something else". #quotes #artforkids #quotesaboutkidsTheir own version of Tower BridgeIt's 8:30am. Kids already in the pool!ProviderYes. It's true. I turned 40 on Wednesday.Sand funToday is our 17th anniversary! Love dancing in the minefields with this woman.Every baby loves bath time!! Big enough for 3 (or 4). #bathtime #lifewithboys #bathtimeinsanityMagazine ad for children's body lotion. Radox??!!??:scream::joy:. #britishbrandingLook what I can do.There's something about this product name that just makes me want to laugh out loud. Guess I can't buy it... since I'm not diabetic:joy: #diabeticvanilla #britishbrandingFor discipline one of my kids was to do some copying. I asked him to bring me a piece of paper and pencil with a clipboard. This was what I got... funny guy!! #lifewithboysBoys playing with Simon's bday present.Captivated audience as Simon opens his presents. #9thbirthdayMaking a mast together. #teamwork #chathamhistoricdockyards #brothers

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

Quote form @amylpollock "Children are always the most creative when they are supposed to be doing something else". #quotes #artforkids #quotesaboutkidsTheir own version of Tower BridgeIt's 8:30am. Kids already in the pool!ProviderYes. It's true. I turned 40 on Wednesday.Sand funToday is our 17th anniversary! Love dancing in the minefields with this woman.Every baby loves bath time!! Big enough for 3 (or 4). #bathtime #lifewithboys #bathtimeinsanityMagazine ad for children's body lotion. Radox??!!??:scream::joy:. #britishbrandingLook what I can do.There's something about this product name that just makes me want to laugh out loud. Guess I can't buy it... since I'm not diabetic:joy: #diabeticvanilla #britishbrandingFor discipline one of my kids was to do some copying. I asked him to bring me a piece of paper and pencil with a clipboard. This was what I got... funny guy!! #lifewithboysBoys playing with Simon's bday present.Captivated audience as Simon opens his presents. #9thbirthdayMaking a mast together. #teamwork #chathamhistoricdockyards #brothers