Date Posted : 10-12-2018

What is Dompdf?

Dompdf  is a HTML to PDF converter. It is a great library and can create a PDF from HTML markup and CSS styles (it’s mostly CSS 2.1 compliant and has support for some CSS3 properties).

Step 1: Initially, download the fresh version of Codeigniter 3 and configure it in xampp.

Step 2: Create the file   name called “ Pdf.php ” . Place this file inside the application/libraries/ and copy the following code.

<?php defined('BASEPATH') OR exit('No direct script access allowed');
	require_once(dirname(__FILE__) . '/dompdf/dompdf_config.inc.php');
	class Pdf extends DOMPDF
	{
		/**
		 * Get an instance of CodeIgniter
		 *
		 * @access	protected
		 * @return	void
		 */
		protected function ci()
		{
			return get_instance();
		}
		/**
		 * Load a CodeIgniter view into domPDF
		 *
		 * @access	public
		 * @param	string	$view The view to load
		 * @param	array	$data The view data
		 * @return	void
		 */
		public function load_view($view, $data = array())
		{
			$html = $this->ci()->load->view($view, $data, TRUE);
			$this->load_html($html);
		}
	}

Step 3: Dompdf: we have to download dompdf library from GitHub, So let’s download from here : Click Here to download dompdf. After download extract it to your “application/libraries” folder and rename it to “dompdf”.

Step 4: In this step, we will add one route “mypdf” for demo, that way when we run this route we will download pdf file, So let’s add following route on your routes.php file.

application/config/routes.php

&lt;?php
defined('BASEPATH') OR exit('No direct script access allowed');


$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['mypdf'] = "welcome/mypdf";

Step 5: In this step we require to add “mypdf” method on welcome controller, So let’s add with following code. you have to just copy of welcome.php controller file:

application/controllers/Welcome.php

&lt;?php
defined('BASEPATH') OR exit('No direct script access allowed');


class Welcome extends CI_Controller {


  /**
    * Get All Data from this method.
    *
    * @return Response
   */
   public function index()
   {
	$this-&gt;load-&gt;view('welcome_message');
   }


   /**
    * Get Download PDF File
    *
    * @return Response
   */
   function mypdf(){


	$this-&gt;load-&gt;library('pdf');


  	$this-&gt;pdf-&gt;load_view('mypdf');
  	$this-&gt;pdf-&gt;render();


  	$this-&gt;pdf-&gt;stream("welcome.pdf");
   }
}

Step 6: Adding View File

Now at last step we require to create “mypdf.php” view file for generate pdf file. So now as below i created “mypdf.php” with some html code, so you have to copy below code and create on view folder:

application/views/mypdf.php

&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
	&lt;title&gt;Codeigniter 3 - Generate PDF from view using dompdf library with example&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;


&lt;h1&gt;Codeigniter 3 - Generate PDF from view using dompdf library with example&lt;/h1&gt;
&lt;table style="border:1px solid red;width:100%;"&gt;
	&lt;tr&gt;
		&lt;th style="border:1px solid red"&gt;Id&lt;/th&gt;
		&lt;th style="border:1px solid red"&gt;Name&lt;/th&gt;
		&lt;th style="border:1px solid red"&gt;Email&lt;/th&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td style="border:1px solid red"&gt;1&lt;/td&gt;
		&lt;td style="border:1px solid red"&gt;Hardik&lt;/td&gt;
		&lt;td style="border:1px solid red"&gt;user@email.com&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td style="border:1px solid red"&gt;2&lt;/td&gt;
		&lt;td style="border:1px solid red"&gt;Paresh&lt;/td&gt;
		&lt;td style="border:1px solid red"&gt;user@email.com&lt;/td&gt;
	&lt;/tr&gt;
&lt;/table&gt;


&lt;/body&gt;
&lt;/html&gt;

Ok, now we are ready to run our PDF generator example. So let’s run below command on your root directory for quick run:

http://localhost/mypdf

CCAvenue CCNon-Seamless PG Integration Date Posted: 22 Nov 2018 Prerequisite  :PHP Basics SEAMLESS INTEGRATION This is for Large Scale Product and organisations who have good finance team to jolt down the financials with the Banks for the DIRECT integrations and with PG Aggregators for the INDIRECT integrations and a good Dev team… Continue Reading CCAvenue CCNon-Seamless PG Integration

Edit the profile details using Angular2 Dated on: 25/10/2018 In this post we are going to see how to edit the profile details using angular 2. In previous post we have seen how to create the sign up form Step 1: Create the new component or new project as you… Continue Reading Edit the profile details using Angular2

PHP :: If…Else Statements Date Posted : 25-Oct-2018 Conditional statements are used to perform different actions based on different conditions. Conditional Statements Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this. In PHP… Continue Reading PHP :: If…Else Statements

How to Install PHP 7.x on CentOS 7 Date posted: 19-oct-2018 In this article, we will installing PHP 7.x on CentOS 7 Server. Step 1: Setup the Webtatic YUM repo Precompiled PHP 7.x binaries are available for CentOS 7 from the Webtatic, IUS, or Remi’s RPM repositories. Below are instructions… Continue Reading How to Install PHP 7.x on CentOS 7

How to install and configure Opencart – 3.0.2 On CentOS – 7. DATE POSTED: 19-10-2018 What is Opencart and its real-time purpose in this world ? OpenCart is a free and open source  online e-commerce web application. It is written in PHP and uses MySQL to store its database. It has… Continue Reading How to install and configure Opencart – 3.0.2 On CentOS – 7.

Insert data into database using codeigniter Date posted: 04-oct-2018 Please follow  the steps to insert data into database using codeigniter Step 1: Create a new file under the path Application/controllers/Insert.php.Copy the below given code in your view. <?php class Insert extends CI_Controller { public function __construct() { //call CodeIgniter’s default… Continue Reading Insert data into database using codeigniter

How to upgrade from PHP 7.0 to PHP 7.1 on Ubuntu Posted Date : 21-09-2018 In this post we will explain upgrade from PHP 7.0 to PHP 7.1 on Ubuntu. We assuming that you have have php 7.0 installed in your server. Please follow the and upgrade the php version… Continue Reading How to upgrade from PHP 7.0 to PHP 7.1 on Ubuntu

Date Posted: 10-09-2018 In this Post we will explain create dynamic menu from database using codeigniter. We assuming that you are familiar with CodeIgniter’s MVC structure, so We did not going to explain what model and controller in CI are. Step 1: Please execute the following command and create the… Continue Reading Create dynamic menu from database using codeigniter