How To Create Pdf Using MPDF Codeigniter 3?

In my previous post, We wrote a article on CodeIgniter 3 PDF Generate Tutorial With Example and in that article We covered mPDF library manual installation step by step, without any types of the run composer. So in this post, We would like to use CodeIgniter 3 as well as composer to install and to load mPDF library.

Here are the simple 5 steps to generate main PDF in the CodeIgniter 3 web application with mPDF: also resolve Error “temporary files directory is not writable mpdf codeigniter”.

Step 1:

first of all you can simple Download and install CodeIgniter.

Also Read: PHP Create PDF file using mpdf

Step 2:

and then Run below composer command to download mPDF library from your web project Directory. It will make a fresh Directory called “vendor” as well as it will download free “mpdf” library into it.

$ composer require mpdf/mpdf

there is my the directory main step 3 and step 4 after installing mpdf

Step 3:

Open application/config/config.php file as well as update you vendor directory path

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

Also Read: PHP How-to create Dynamic PDF Files using FPDF

Step 4:

Use mPDF library inside in your controller, here is the sample:

<?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('html_to_pdf',[],true);
		$mpdf->WriteHTML($html);
		$mpdf->Output(); // opens in browser
		//$mpdf->Output('pakainfo.pdf','D'); // it downloads the file into the user system, with give name
	}

}

Step 5:

simple last step to create a view called html_to_pdf.php file in server side in your view Directory with below html part.

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>Welcome to pakainfo</title>
</head>
<body>

<div id="container">
	<h2>Welcome to pakainfo!</h2>

	<div id="body">
		<p>If you have not found Tamilrockers website worth or have not liked by pakainfo.</p>

		<p>TamilRockers New Link: Want to know the way to get Tamilrockers New link ? or Tamilrockers Latest URL?</p>
		<code>application/views/welcome_message.php</code>

		<p>tamilrockers new website</p>
		<code>application/controllers/Welcome.php</code>

		<p>TamilRockers New Website 2020.. how to download tamilrockers new link without using any VPN applications enter tamil rockers domain <a href="user_guide/">tamilrockers new link</a>.</p>
	</div>

</div>

</body>
</html>

Also Read: Laravel 7 Generate/Create PDF File Tutorial From Scratch

Step 6:

That’s it. Very quick and simple. Now access your CodeIgniter application, you should get similar results:


Related FAQ

Here are some more FAQ related to this Article:

  1.   Web Services Tutorial In PHP For Beginners
  2.   Vue js Laravel 5.8 File Upload Tutorial
  3.   check if folder exists before create directory Laravel
  4.   Vuejs filterBy orderBy CustomFilter Example
  5.   Email Verification in Laravel 5.7 Example Tutorial
  6.   jQuery Check duplicated value in array
  7.   Generate PDF in Laravel 5.8 example
  8.   Simple Jquery Fancybox Popup
  9.   jQuery Time Range slider Get Value using JavaScript
  10.   Concatenation string and Class in VueJS