8bitOrange

  • Archive
  • RSS
  • Ask me anything

CakePHP 1.3 and DomPDF

After a lot of ridiculous meddling with code, I took a break and came back to trying to get DomPDF working with CakePHP 1.3. There were a few major problems, but most have been fixed now with only a couple of styling issues to make this work.

The goal was to output an already styled HTML page to PDF with as little effort as possible, so that we could then reuse this package across multiple sites without having to relayout the pages or reconfigure the php each time. DomPDF appeared to be a good way to go about this, but the first error I was running into was DomPDF’s autoloader attempting to load cake core classes from its own include directory. I tried to figure out where this was coming from but was hitting a wall over and over again, the fix ended up being pretty simple and its this:

In the dom_configure.inc.php just add an if statement as follows

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

This prevents from loading anything that is not in the DomPDF includes folder. This was the first major hurtle. Still working out some major kinks on how to display the pdf.

    • #code
    • #html to pdf
  • 2 years ago
  • Permalink
  • Share
    Tweet
← Previous • Next →

About

I'm a nerd lost on the internet. I build things with code and write things with words. Fork me on GitHub

Pages

  • I am Matt Caron and I am addicted to the internet
  • Code Blog
  • Resume
  • Stack Overflow
  • My Photography
  • Nerd Appropriate
  • I'm Google-able

Twitter

loading tweets…

  • RSS
  • Random
  • Archive
  • Ask me anything
  • Mobile

Effector Theme by Carlo Franco.

Powered by Tumblr