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:

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.

0 0 vote
Article Rating
Subscribe
Notify of
guest
24 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Amadeus Anderson
Amadeus Anderson
2 years ago

I’m getting a
Message: Class ‘MpdfMpdf’ not found error. How to fix it

arjun
2 years ago

is your issue resolved?

Monika Bombol Lagha
Monika Bombol Lagha
1 year ago
Reply to  arjun

I have the same problem. Realy, how to solve it? Can you give any expamles?

Kiran Burugula
Kiran Burugula
2 years ago

Hi Arjun, Nice tutorial. Please let me know how to display google api charts in pdf

arjun
2 years ago
Reply to  Kiran Burugula

I will try in my free time, it should work directly.

Kiran Burugula
Kiran Burugula
2 years ago
Reply to  arjun

please.once you done update me.thanks in advance

Prasen Patil
Prasen Patil
2 years ago
Reply to  Kiran Burugula

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.
html2canvas($(‘#chart’),
{
onrendered: function (canvas) {
var href = canvas.toDataURL();
$(‘#img_val’).val(href);
document.getElementById(“myForm”).submit();
}
});
Reply if success

Harshad Dusane
Harshad Dusane
2 years ago

Hi Arjun,
I’m getting a Message: Class ‘MpdfMpdf’ not found error.

arjun
2 years ago
Reply to  Harshad Dusane

Just added download url,You can download and try.

trilok kumar
trilok kumar
2 years ago
Reply to  arjun

I have downloaded code and install mpdf from composer but i am getting error Class ‘MpdfMpdf’ not found

Aditya Patel
Aditya Patel
2 years ago

mpdf support css?

arjun
2 years ago
Reply to  Aditya Patel

yes it will – here you go – https://mpdf.github.io/css-stylesheets/supported-css.html

I will also recommend you to check DOMPDF library https://arjunphp.com/dompdf-library-using-codeigniter-3/

Arpit
Arpit
2 years ago

Mpdf is not showing inr symbols in pdf it is replaced by a box, what’s the solution??

Alphi
Alphi
2 years ago

Class ‘MpdfMpdf’ not found..please help to solve this issue

Vilas
Vilas
2 years ago

Thank you its working, But it will take too much time for 2-3 lakh while data exporting. any solutions???

arjun
2 years ago
Reply to  Vilas

Is it taking time for forming HTML template or HTML to PDF conversation

gopal venu
gopal venu
2 years ago

$ 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.

arjun
2 years ago
Reply to  gopal venu

run command without $

ahmed
ahmed
1 year ago

mpdf support bootstrap ?

Heng Wendy
1 year ago

it show me hundred of white pages pdf

Developer
Developer
10 months ago

Fatal error: Uncaught Error: Class ‘MpdfMpdf’ not found in codeigniter

Developer
Developer
10 months ago

Fatal error: Uncaught Error: Class ‘MpdfMpdf’ not found in codeigniter version 2.1.4

Hitaishi
Hitaishi
7 months ago

I am having issues in displaying “₹” currency in mPdf. I am using mPDF version 5.7. Can you please tell me how to add rupee font in this version so I can dispplay ₹ currency in pdf.

nik
nik
7 months ago

thanks

DMCA.com Protection Status
24
0
Would love your thoughts, please comment.x
()
x