Generate PDF using mPDF in Codeigniter

Kailash Singh

Generate PDF using mPDF in Codeigniter

Published Oct 16,2021 by Kailash Singh

0 Comment     515 Views    

In this tutorial, we are going to teach, how to generate PDF using mPDF in Codeigniter.

Step 1 : Open your project and run your cmd screen and then 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.

eg: composer require mpdf/mpdf

Like this : 


Here is the directory structure after installing mPDF


Step 2: Open application/config/config.php file and set you vendor directory path and also enable composer_autoload.

$config['composer_autoload'] = TRUE;
$config['composer_autoload'] = 'vendor/autoload.php';


Step 4: Open your controller file and Use mPDF library inside in your controller.

defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller {

 public function index()

  $mpdf = new \Mpdf\Mpdf();

  //create html
  $html ='<h1>Elevenstech Web Tutorials</h1><h3>Generate PDF using mPDF in Codeigniter</h3>';








Comments ( 0 )