Generating a PDF in CodeIgniter using MPDF

Many times we need to generate reports in our applications it may be in the form of charts, excel sheets, or PDF.

I assume that you are at an intermediate level and able to generate the report in HTML form and now only facing problem to convert it into PDF format.

Here we are going to Generate a report in PDF format. There are many libraries available for these purpose like FPDF, PDF etc. In our case i used MPDF and CodeIgniter version 2.1.2 .  you can download MPDF from here .

Now, you need to extract the MPDF and put all the files at ./application/helpers/mpdf.  We have to create a custom helper. Here i create a helper file as /application/helpers/My_Pdf_helper.php. The code will be as follows :

Now You need to use this helper into your controller and use into function.
And the function will be look like as follows :-

This function will directly download the pdf file.

About the Author: