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 the composer. So in this post, I would like to use CodeIgniter 3 and composer to install and load the 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 the below composer command to download the mPDF library from your project folder. It will create a new folder called “vendor” and it will download the “mPDF” library into it.
Here is 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 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.