How to Generate PDFs in CodeIgniter with mPDF

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');
}

}

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>

I hope you get an idea about Generating a PDF in Codeigniter using mPDF.


#codeigniter #mPDF

How to Generate PDFs in CodeIgniter with mPDF
1.00 GEEK