How to use mPDF In Yiiframework 2

/ By Arjun / Published on November 7, 2015

Hello there, Today I would like to show you how to integrate mPDF library with Yii framework 2.First, let me give you some basic information about mPDF. mPDF is a PHP Class by using this we can easily generate PDF files from HTML templates so you can style your HTML template as you wish. Here are the simple steps to use mPDF with the YII2 framework.

You can install in tow way – using composer or you can install manually.

Install mPDF Using Composer

Require this package in your composer.json by adding "mpdf/mpdf":"*" or you can directly run php composer.phar require mpdf/mpdf "dev-master" or composer require mpdf/mpdf "dev-master" it will update your composer.json and downloads mPDF library.

Next, update Composer from the Terminal

Install mPDF Manually

Download mPDF from : and Extract it to your vendor/ folder of your yii2 application. Now rename and change the file path as mpdf/mpdf/ and See the below image for file structure.

 How to use mPDF In Yiiframework 2

Now go to vendor/composer/autoload_namespaces.php file and add the below line to array

How to use – Create PDF Using mPDF

Below is simple example – you just need to import mPDF by using use mPDF; and the crate object for mPDF. using generated object you call all of mPDF methods.


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 votes
Article Rating
Notify of
Newest Most Voted
Inline Feedbacks
View all comments
Daniel Lucena
5 years ago

Sorry but mannualy instalation not work for me! “Class ‘mPDF’ not found”

and via composer i will broke my system!

Ramssés Gómez
Ramssés Gómez
5 years ago
Reply to  Daniel Lucena

Did you try to remove the mannualy files installed and don’t use their in the code?

5 years ago

Following error with manual installation .

Class ‘mPDF’ not found

Junior Vilas Boas
Junior Vilas Boas
4 years ago

failed to open stream: No such file or directory

Would love your thoughts, please comment.x