how to generate pdf using mpdf in codeigniter?

Today, We want to share with you how to generate pdf using mpdf in codeigniter?.In this post we will show you mpdf library for php 7, hear for export data to pdf in codeigniter we will give you demo and example for implement.In this post, we will learn about generate pdf in PHP with an example.

how to generate pdf file from database in codeigniter?

Using mPDF with CodeIgniter 3

$ composer require mpdf/mpdf

application/config/config.php

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

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();
 $html = $this->load->view('generated_pdf_file',[],true);
 $mpdf->WriteHTML($html);
 $mpdf->Output(); // opens in browser
 //$mpdf->Output('arjun.pdf','D');
 }
 
}

Free Live Chat for Any Issue

create a view called generated_pdf_file.php
generated_pdf_file.php

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="utf-8">
 <title>Welcome to Pakainfo.com</title>
</head>
<body>
 
<div id="container">
 <h2>Welcome to Pakainfo!</h2>
 
 <div id="body">
 <p>TamilRockers is a very popular Indian torrent website where you will get a collection of unlimited Tamil and Bollywood movies.</p>
 
 <p>Because tamilrockers website is blocked by the telecommunications authorities of India(ISP) to prevent movie piracy. I will be updating regularly. </p>
 <p>TamilRockers. TamilRockers is a public torrent website. TamilRockers website uploads the pirated versions of Tamil, Telugu, Hindi, English, ...</p>

 <p> <a href="https://www.pakainfo.com/tamilrockers-new-domain/">tamilrockers new domain</a>.</p>
 </div>
 
</div>
 
</body>
</html>

Download

I hope you get an idea about Generating a PDF in Codeigniter using mPDF.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.