Easily integrate mPDF into CodeIgniter Framework

Got the tip from here: http://davidsimpson.me/2013/05/19/using-mpdf-with-codeigniter/
On this previous post, I tell you on how to easily integrate ezPDF into CodeIgniter but the problem is: the PDF generation is not template-based. So, you have to write a lot of codes just to generate simple PDF output.
By integrating mPDF into your CodeIgniter-based site, you can create a PDF output via templating system just as simple as loading a view and pass through some variables into it. mPDF also support CSS, so, you can style your HTML template as cool as you wish.
Here’s the steps-by-steps guide:

  • Download mPDF from http://www.mpdf1.com/mpdf/index.php?page=Download . Remember to download the “Full installation” first (a bit big) and then you can download the patch/upgrade (a little smaller size)
  • Extract it to your application/third_party/ folder of your CodeIgniter. Your third_party folder would be like this:

    mPDF in third_party folder

    mPDF in third_party folder

  • Create a new file in your application/libraries/ name it m_pdf.php and these are the contents:

  • Your library folder would be like this:
    mPDF in the library folder

    mPDF in the libraries folder

  • And it’s done!

How to use it?
Create a CodeIgniter “view file“, let’s named it pdf_output.php:

Now, inside the controller, you can do this:

Leave a comment ?

18 Comments.

  1. previously i was using mpdf, it turns out very slow to convert a lot of pdf, i ended up using wkhtmltopdf instead , it’s very fast.. still the best free html to pdf solution

    • Does wkhtmltopdf working on shared hosting? Never tried it on shared hosting before.
      Soon I’ll release my new website that utilize wkhtmltopdf(and wkhtmltoimage). 🙂

      • I use shared hosting webfaction.com, i was able to run it perfectly. i never tried on cpanel based shared hosting though. what is your new website ? vrank.org ?

  2. Just wondering what the advertising network are you using on ytconv.net that shows “pl
    ay download button” ads

  3. php: Matrix operation library for CodeIgniter - pingback on 2014/09/08 at 13:59
  4. how to work it with css file ?>

  5. it works for me.thank u.can u tell me how can insert sql query in to the pdf.please

  6. hi, am getting error like this, what to do ?
    An Error Was Encountered

    Unable to load the requested class: M_pdf

  7. how can i print bangla font correctly using mpdf??

  8. //$pdf->Output($pdfPath, ‘D’); this line not works

  9. Aji Bhaskar

    Database values were not printed, showing errors. How can i solve this problem

Leave a Reply

Trackbacks and Pingbacks:

%d bloggers like this: