Tuesday, September 15, 2015

PDF generate in Codeigniter using DOMPDF




In this topics, we will discus about how to generate PDF using DOMPDF with Codeigniter Framework.

Step 1: Download Pdf.php library from https://github.com/chrisnharvey/CodeIgniter-PDF-Generator-Library/tree/master/libraries and copy it to codeigniter library directory.

Step 2: Download DOMPDF from https://github.com/dompdf/dompdf/tree/v0.6.2 or https://code.google.com/p/dompdf/downloads/list. Extract it and copy the dompdf folder to codeigniter library directory.

Step 3: Open Welocme Controller or any other. Create a method on this controller as bellow-

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
function mypdf(){
$this->load->library('pdf');
$this->pdf->load_view('common/template');
$this->pdf->render();
$this->pdf->stream("welcome.pdf");
}

}
Here mypdf function (you can give any name of this function) of Welcome controller will generate pdf file of common/template view file.

In the mypdf  function we first load pdf library and then load view file then render it and stream.

Ok it is done. you can try and enjoy it.

To learn about mPDF please go the following link

PDF Generate in Codeigniter using mPDF

29 comments :

  1. Replies
    1. Thanks Shruthi Kumari for reading this tutorial.

      Delete
  2. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.
    Regards,
    SAS Training in Chennai| SAS Course in Chennai

    ReplyDelete
  3. defined('BASEPATH') OR exit('No direct script access allowed');
    here, BASEPATH = base_url ???

    ReplyDelete
  4. HI, it's working good, but I want to generate pdf for 3 php files at a time, please help me.

    ReplyDelete
  5. I placed your code in my project but when i run it, it display blank page. I think it has problem to find pdf.php file from library directory.

    ReplyDelete
    Replies
    1. The article for DOM version 0.6.* https://github.com/dompdf/dompdf/tree/v0.6.2


      So try it with the specific version.

      Delete
  6. The best article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.
    the best infomtica training institute

    ReplyDelete
  7. You Code show me error like this

    Severity: Warning

    Message: require_once(C:/xampp/htdocs/ctscms/application/libraries/dompdf/include/functions.inc.php): failed to open stream: No such file or directory

    Filename: dompdf/dompdf_config.inc.php

    Line Number: 52

    Backtrace:

    File: C:\xampp\htdocs\ctscms\application\libraries\dompdf\dompdf_config.inc.php
    Line: 52
    Function: _error_handler

    File: C:\xampp\htdocs\ctscms\application\libraries\dompdf\dompdf_config.inc.php
    Line: 52
    Function: require_once

    File: C:\xampp\htdocs\ctscms\application\libraries\Pdf.php
    Line: 14
    Function: require_once

    File: C:\xampp\htdocs\ctscms\application\third_party\MX\Loader.php
    Line: 173
    Function: _ci_load_library

    File: C:\xampp\htdocs\ctscms\application\modules\requisition\controllers\Welcome.php
    Line: 5
    Function: library

    File: C:\xampp\htdocs\ctscms\index.php
    Line: 315
    Function: require_once


    Fatal error: require_once(): Failed opening required 'C:/xampp/htdocs/ctscms/application/libraries/dompdf/include/functions.inc.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\ctscms\application\libraries\dompdf\dompdf_config.inc.php on line 52
    A PHP Error was encountered

    Severity: Compile Error

    Message: require_once(): Failed opening required 'C:/xampp/htdocs/ctscms/application/libraries/dompdf/include/functions.inc.php' (include_path='.;C:\xampp\php\PEAR')

    Filename: dompdf/dompdf_config.inc.php

    Line Number: 52

    Backtrace:

    ReplyDelete
    Replies
    1. The article for DOM version 0.6.* https://github.com/dompdf/dompdf/tree/v0.6.2

      Delete
  8. • Nice Blog It's such a useful information to all.
    tib co training in chennai

    ReplyDelete
  9. The best article! I found some useful information in your blog,
    sas training in chennai

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. how to set pdf file using database.. procedure

    ReplyDelete
  12. Nice Article. Thanks for sharing usefull Information and I have seen more info on Top Hotel Management College with Affiliated to Osmania University

    ReplyDelete
  13. This information really worth saying, i think you are master of the content and thank you so much sharing that valuable information and get new skills after refer that post.
    Java Training in Chennai

    ReplyDelete

 

Copyright @ 2014 Tech Tutorial .