Using mPDF with CodeIgniter 3

In my previous post, I wrote a tutorial on Generating a PDF in Codeigniter using mPDF and in that tutorial I covered mPDF library manual installation steps, without composer. So in this post, I would like to use CodeIgniter 3 and composer to install and to load mPDF library.

Here are the steps to generate PDF in the CodeIgniter 3 application with mPDF:

Step 1: Download and install CodeIgniter.

Step 2: Run below composer command to download mPDF library from your project folder. It will create a new folder called “vendor” and it will download “mpdf” library into it.

Here is my the directory structure after installing mpdf

Step 3: Open application/config/config.php file and set you vendor directory path

Step 4: Use mPDF library inside in your controller, here is the sample:

Step 5: create a view called html_to_pdf.php file in side in your view folder with below html

Step 6: That’s it. Very quick and simple. Now access your CodeIgniter application, you should get similar output:

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets. Protection Status