How to generate and download PDF in codeigniter using mPDF ?

Hi User, Thanks for visiting this blog for your query. With the help of this article you will learn about how to generate PDF file in codeigniter with the help of mPDF Library.

Steps for configuring mPDF in codeigniter to generate and download pdf

1. Download and extract mPDF

Download mPDF from : and Extract it to your application/third_party/ folder of your CodeIgniter.

2. Create a new file in your application/libraries/ name it M_pdf.php

if (!defined('BASEPATH')) exit('No direct script access allowed');
include_once APPPATH.'/third_party/mpdf/mpdf.php';
class M_pdf {
public $param;
public $pdf;
public function __construct($param = "'c', 'A4-L'"){
$this->param =$param;
$this->pdf = new mPDF($this->param);

3. Create a file in controller and paste the below code

if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class PDF extends CI_Controller {
public function generatePDF(){
// Name of your pdf file
$filename = time()."_filename.pdf";
// fetch data from the database
$data = $this->YourModel->modelMethod();
// pass data to view
$html = $this->load->view('pdfview', $data, true);
// load the library
//download it D save F.
$this->m_pdf->pdf->Output("./assets/doc/".$filename, "F");
echo "PDF has been generated successfully!";
/* End of file pdf.php */
/* Location: ./application/controllers/pdf.php */

I hope this will help out to resolve your query. If you found any issue please share it in the comment box.

Web Hosting

Ankit Pathak

Meet me, I'm Ankit Pathak an energetic, ambitious person who has converted several ideas into the reality. I'm a web developer & graphic designer which sometimes give me an added advantage to beautify my development skills.


  1. Omkar Deshmne says:

    file will be store on server but not download in chrome browser when using D in place of F

  2. janani says:

    can u tell how to save as pdf?

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.