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

Work day in London.Micah's new persona is Indian Jones. And he's never even seen the movie! Check out that hat.A very cold walk today. With horses in tow.The real Epping forest.Growing up in the city has taught my boys a few thingsCricket playersIsaac with the car he would love to ownAll aboardPhotoThis guy greeted us on our walk on the common today. He and his sidekick haven't been there before, so when they came trotting round the corner, we Americans got a bit of an adrenaline rush til we figured out he was SUPER friendly!! #englandtrip2017 #eppiSome luck I have these days :stuck_out_tongue_winking_eye:Easter card construction messPre-Easter cookout at the Nicholson's. Quite the crowd!A walk in the forestDate night in Cambridge.

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

Work day in London.Micah's new persona is Indian Jones. And he's never even seen the movie! Check out that hat.A very cold walk today. With horses in tow.The real Epping forest.Growing up in the city has taught my boys a few thingsCricket playersIsaac with the car he would love to ownAll aboardPhotoThis guy greeted us on our walk on the common today. He and his sidekick haven't been there before, so when they came trotting round the corner, we Americans got a bit of an adrenaline rush til we figured out he was SUPER friendly!! #englandtrip2017 #eppiSome luck I have these days :stuck_out_tongue_winking_eye:Easter card construction messPre-Easter cookout at the Nicholson's. Quite the crowd!A walk in the forestDate night in Cambridge.