Bladephp: Now with 8+ codeigniter, php, and laravel project 8+ php project From $37/Month From Rs. 2499/Month

How to Create PDF using DOMPDF in Codeigniter

How to Create PDF using DOMPDF in Codeigniter

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

We are going to use a third-party library called Dompdf that enables us to create PDFs and save them to the server or directly display them.

Step 1: Create Librarie (application/libraries/Dompdf_gen.php)

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Dompdf_gen {
    public function __construct() {
        require_once APPPATH.'third_party/dompdf/';
        $pdf = new DOMPDF();
        $CI =& get_instance();
        $CI->dompdf = $pdf;

Step 2: Call Librarie in Controller

public function __construct() {
    parent::__construct ();

Step 3: Controller Function Code

$pdfname = 'scheduling_'.date('YmdHis').".pdf";
$html = '
    table {
      display: table; border-collapse: collapse;
    .pricedetail tr td
        font-size: 10px;
    .pricedetail tr th
        font-size: 10px;
<table border="1" width="100%" class="pricedetail">
$output = $this->dompdf->output();
file_put_contents('public/pdf/'.$pdfname.'', $output);


Html code work in comment box

Related Post