how to generate pdf using dompdf in codeigniter


 dom pdf is a php library with the help of which you can generate dynamic page pdf!

In this post I have told you how to use dom pdf in CodeIgniter!

In this Post, I would like to present how to use domPdf library with codeigniter to generate PDF reports. The HTML to PDF conversion can be easily done using domPdf PHP library.

 

What is domPdf ?

DomPdf is a PHP library that produces PDF from HTML content. To generate reports in pdf we can use dompdf written in PHP.

 

Key Features:

a.) Support external stylesheets.

b.) Support complex tables.

c.) Image Support.

d.) Inline PHP support.

 

Requirements

PHP version 7.1 or higher

DOM extension

MBString extension

php-font-lib

php-svg-lib

GD Extension (For image processing)

I will show you step by step dompdf setup with codeigniter.I am assuming that you already know about setup of codeigniter.If you have any issue with codeigniter setup then you can check this post

 

Display Images

To display remote url images in pdf you need to set true remote enabled in dompdf options.Find isRemoteEnabled option in the file named options.php located in dompdf/src and set True.

 

Thank you for reading this post. we hope you like this Post, Please feel free to comment below, your suggestion and problems if you face – let us know. We’d love to help.

Our Best Popular Projects & Posts

Post Link
School Management System With Full Source Code In php click here
ecommerce project in php click here
simple login and registration form in php click here
Synopsis for online rooms booking project based on PHP click here
add multiple images in codeigniter click here
beginners project in php with source code click here
dynamic country state dropdown in codeigniter click here
how to generate pdf using dompdf in codeigniter click here
add 1 day to current date in php click here
how to check website/blog responsive or not? click here
employee attendance management system project in php with source code click here
Select one checkbox and disable others click here
printing div content with css applied click here
best restaurants management system in php click here
Preview an image before it is uploaded using jquery click here
text editor in jquery click here
data table with export button in html click here
add multiple images in codeigniter click here
codeigniter some steps to install on Your server click here
ajax in php/codeigniter click here
Create Simple API CRUD with PHP and MySQL click here
How to integrate bootstrap theme in codeigniter click here
how to prepare for interview click here
Convert a date format in PHP click here
how to export html table to excel in jquery click here
how to create duplicate google peg using ajax click here
how to make dropdown searchable in html using jquery click here
how to find retirement date in php click here
online food order system in php with source code click here
school management project admin panel in php click here




 Step 1: Download DOMPDF . Paste it into application\libraries folder

            सबसे पहले आपको DOMPDF लाइब्रेरी को डाउनलोड कर लेना है!और एप्लीकेशन के अंदर    

            लाइब्रेरी का फोल्डर है उसके अंदर इस पीडीएफ लाइब्रेरी को रख देना है


Step 2: Create a file name named Pdf.php into application\libraries folder and paste below code.

           

            और pdf.php नाम की फाइल वहां पर बना देनी है और उस फाइल में नीचे कोड लिखा है उसे उस कोड   

            को पेस्ट कर देना है!

<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');  
 
require_once 'dompdf/autoload.inc.php';

use Dompdf\Dompdf;

class Pdf extends Dompdf
{
    public function __construct()
    {
         parent::__construct();
    }
}

?>
Step 3 : Now create a controller that renders html view to PDF.

           अब एक कंट्रोलर बनाएं जो html व्यू को पीडीएफ में रेंडर करे। और पीडीएफ लाइब्रेरी को लोड करें

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

class Home extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->library('pdf');
      
    }



    public function index()
    {  
      $data['result']=$this->Common_model->get_run("SELECT * from tbl_student ");
     
        //$data = 'content/dashboard';
        $this->load->view('view_class', $data);
       
    }

    public function pdf()
    {
        if($this->uri->segment(3))
        {  

                

            $id = $this->uri->segment(3);
            $table='tbl_student';
        $res = $this->Common_model->getdata_one($table,$id);
            $html_content = '<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
                 ';
                 foreach ($res as $key => $value) {
                     $fname = $value['fname'];
                     $lname = $value['lname'];
                     $gender = $value['gender'];
                     $address = $value['address'];
                     $pic = $value['pic'];
                    
                 }
            $html_content.='<div class="body"><h1 align="center">Student List</h1>
                            <div class="table-responsive">
                                <table class="table table-bordered table-striped table-hover dataTable js-exportable">
                                    <thead>
                                        <tr>
                                           <th>First Name</th>
                                            <th>Last Name</th>
                                          
                                            <th>Genders</th>
                                            <th>Address</th>
                                            <th>Image</th>
                                           
                                            
                                        </tr>
                                    </thead>
                                   
                                    <tbody>';


             $html_content .= '  <tbody>


                                          
                                          
                                    

                                      
                                        <tr>
                                            <td>'.$fname.'</td>
                                            <td>'.$lname.'</td>
                                            <td>'.$gender.'</td>
                                            <td>'.$address.'</td>

                                            <td><img src="'.base_url().'upload/'.$pic.'"  style="height="60px" width="60px""></td>
                                         
                                        </tr>
                                     
                                     
                                       
                                    </tbody>
                                </table>';
            $this->pdf->loadHtml($html_content);
            $this->pdf->render();
            $this->pdf->stream("".$id.".pdf", array("Attachment"=>0));
        }
    }



    
}

                                   


                               



download




 

 











 

 


 

0 Comments