Sunday, June 19, 2011

Use dompdf in CodeIgniter

What is dompdf ?
dompdf is the html to pdf converter, basically it is the rendering enjine to
convert html to pdf, written in PHP. It is working with only PHP 5,
so your sever must run with PHP 5.

Why we use dompdf at CodeIgniter ?
CodeIgniter is the PHP framework, used for making MVC based application. if your application need pdf rendering from html files, it is good to use dompdf.

How to install and use dompdf
Installation is very simple, just download the dompdf api. After downloading, you unzip the file, and copy the dompdf folder and paste it to CodeIgniter main folder where you see applications and system folders. After instaling in your application, go to your controller function and put the code. When you call the function through th controller the code execute with the view.

#1 $path = getcwd()."/dompdf/";
#2 require_once($path);
#3 $html = $this->load->view('print_month_reoprts', $var_data, true);
#4 $dompdf = new DOMPDF();
#5 $dompdf->load_html($html);
#6 $dompdf->render();
#7 $dompdf->stream("my_pdf.pdf", array("Attachment" => 0));

Thanks for your patience to read this, follow me @rajeswar


  1. it stop near require once
    after ceode not execute

  2. Please check your $path = getcwd()."/dompdf/";