Generate PDF using mPDF in Codeigniter

Generate PDF using mPDF in Codeigniter
Published Oct 16,2021 by Kailash Singh
0 Comment 2556 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.
<?php
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>';
$mpdf->WriteHTML($html);
$mpdf->Output();
}
}
?>
Comments ( 0 )
SEARCH POST HERE
Support Us
Subscribe My YouTube Channel
Join Our Telegram Channel & Support Eachother
CATEGORIES
INTERVIEW QUESTIONS
PROJECT SOURCE CODE
POPULAR POSTS
Elevenstech Web Tutorials
Elevenstech Web Tutorials helps you learn coding skills and enhance your skills you want.
As part of Elevenstech's Blog, Elevenstech Web Tutorials contributes to our mission of “helping people learn coding online”.
Read More
Newsletter
Subscribe to get the latest updates from Elevenstech Web Tutorials and stay up to date