DomPDf Integration In Codeigniter With Example

Dompdf is an PHP class for generating pdf documents from html.Dompdf is free to use.we will use following step for DomPDf integration with Codeigniter.

Step 1

To Download DomPDf Click Here.

Step 2

Unzip the above download inside application/libraries/dompdf.

Step 3

Create a new file inside application/libraries/Pdf.php

if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once(dirname(__FILE__) . '/dompdf/');
use Dompdf\Dompdf;
class Pdf extends DOMPDF
    function __construct()
/* */  
/* End of file Pdf.php */
/* Location: ./application/libraries/Pdf.php */
Step 4

Create Controller file inside application/controllers/dompdf.php.

class dompdf extends CI_Controller{
      function __construct() { 
 function index()
 $dompdf = new Dompdf\Dompdf();y
 // Set Font Style
 $dompdf->set_option('defaultFont', 'Courier');
 $html = "<p style='text-align: center'>My First Dom Pdf Example</p>";
 // To Setup the paper size and orientation
 $dompdf->setPaper('A4', 'landscape');
 // Render the HTML as PDF
 // Get the generated PDF file contents
 $pdf = $dompdf->output();
 // Output the generated PDF to Browser