How to add Google ReCAPTCHA in PHP Codeigniter Date: 09-05-2020 Introduction: reCAPTCHA is a free service from Google that helps protect websites from spam and abuse. It is verifying a user is a human or robot. Google reCAPTCHA show some images and give hint in text and ask users to select appropriate images… Continue Reading How to add Google ReCAPTCHA in PHP Codeigniter

How to debug in Codeigniter Date : 09/11/2019 Introduction We can use functions like echo, print_r(), var_dump() or log_message() to print values both in log files and also in browser. Other than log_message() other print methods will not print values in log_message. echo – used to simply display the content.… Continue Reading How to debug in Codeigniter

 How to Connect MySQL Database Remotely using Codeigniter Date : 08/10/2019 Introduction You can connect remote database with other for development in codeigniter project development. There are few things have to checked to connect remote database for your codeigniter project. The checks are summarised in the following. Enter valid details… Continue Reading How to Connect MySQL Database Remotely using Codeigniter

HOW TO LOAD MULTIPLE DATABASES IN CODEIGNITER FRAMEWORK. Date posted :26/04/2019 LOAD MULTIPLE DATABASES: Most importantly, codeIgniter has a config file that you can store your database connection values such as username, password, database name. Therefore this config file located at application/config/database.php. hostname – The hostname of your database server.… Continue Reading HOW TO LOAD MULTIPLE DATABASES IN CODEIGNITER FRAMEWORK.

Create Dynamic Bootstrap Rows & Columns in PHP based on arrays DATE POSTED: 10/04/2019 In this post we will explain how to create dynamic bootstrap rows and columns in PHP based on arrays. Please use the following steps and create the dynamic bootstrap rows and columns. STEPS In this post… Continue Reading Create Dynamic Bootstrap Rows & Columns in PHP based on arrays

CodeIgniter Queries DATE POSTED: 03/04/2019 In this post we will explain basic CodeIgniter Queries. What is CodeIgniter? CodeIgniter is a powerful PHP framework with a very small footprint, built for developers who need a simple and elegant toolkit to create full-featured web applications. Today we are going to discuss about… Continue Reading CodeIgniter Queries

Date :28/03/2019 What is codeigniter? Codeigniter is a php framework to develop the application. Therefore, it provides the many libraries for connecting to the database. Codeigniter simple Add, Edit, Delete, View However, we create database and table. Firstly, database name is considered to be as ‘form’. similarly, creating a table… Continue Reading CODEIGNITER: SIMPLE ADD, EDIT, DELETE, VIEW

VALIDATION FORM IN CODEIGNITER USING SESSION LIBRARY Date :28/03/2019 Introduction: The following tutorial implementing form validation using session library in codeigniter. First of all, we should create database and table. we can create database client and we can create table form . To implement the form validation we need to… Continue Reading VALIDATION FORM IN CODEIGNITER USING SESSION LIBRARY

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

<?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

<?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->load->view('welcome_message');
   }


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


	$this->load->library('pdf');


  	$this->pdf->load_view('mypdf');
  	$this->pdf->render();


  	$this->pdf->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

<!DOCTYPE html>
<html>
<head>
	<title>Codeigniter 3 - Generate PDF from view using dompdf library with example</title>
</head>
<body>


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


</body>
</html>

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