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.

Using mPDF with CodeIgniter 3

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:

By Arjun

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

22 replies on “Using mPDF with CodeIgniter 3”

hello ,
I too got same issue. Got with some solution.
If you are ok with displaying your charts on HTML pages then simply convert your chart into image then pass that one to mpdf.
by js
try this.
onrendered: function (canvas) {
var href = canvas.toDataURL();
Reply if success

$ composer require mpdf/mpdf this command is not working for me. it shows error ‘$’ is not recognized as an internal or external command,
operable program or batch file.

Leave a Reply

Your email address will not be published. Required fields are marked *