Create PDF in CodeIgniter Part II

In the previous post, I have made the article made ​​a pdf file on codeigniter. From that article I create using tcpdf And now, I will share using dompdf. Why dompdf? Because dompdf is easy to use.. And you can compare between tcpdf with dompdf. And this is step to install (join) dompdf with CodeIgniter.

  1. First We must download library dompdf.
  2. Examples, the file save to folder Downloads. And now open your terminal/konsole. And write some of these orders:
    $ cd Downloads
    $ unzip
  3. After uncompressed, now open folder Codeigniter-DOMPDF-master/third_party and cut folder dompdf and paste to your CodeIgniter/application/third_party to be like this:

  4. And Open folder Codeigniter-DOMPDF-master/controllers and cut file dompdf_test.php and paste to your CodeIgniter/application/controllers/ to be like this:
  5. And the last open folder Codeigniter-DOMPDF-master/libraries and cut file dompdf_gen.php and paste to your CodeIgniter/application/libraries to be like this:
  6. And now open your CodeIgniter/index.php/dompdf_test.php, and you can get file download pdf from view welcome_message

If you want activated preview before download, you can change dompdf_test.php code to be like this:

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

class Dompdf_test extends CI_Controller {

	 * Example: DOMPDF 
	 * Documentation: 
	public function index() {	
		// Load all views as normal
		// Get output html
		$html = $this->output->get_output();
		// Load library
		// Convert to PDF
		//or without preview in browser


  1. Hello, I have implemented Dompdf as as you indicate it, but me a problem arises, the page html that I have must go out on only one page of the pdf … but salt 3 pages: first blank, the second one with an imgen that loaded and in the third one does the rest of the html appear, you have some idea because this can happen?
    pardon but a translator spoke Spanish and used to write yourself
    thank you and greetings

  2. i copied and pasted above code it works to download pdf but while opening the pdf it displaying that the file corrupted

    1. Check your code again. If u’ve wrong code. Example closed tag empty like this <p>blablabla… and empty </p> That code can create the pdf corrupted..

  3. how can i generate a pdf file with some chinese word?
    i tried to type some chinese word and generate a pdf. All the chinese(三字經) will diplay like this “《三å-—經》”

  4. PDF generated successfully but External css class not apply in created pdf ..any one have solution for external css also effect in created pdf .

  5. You share interesting things here. I think that your website can go viral easily, but
    you must give it initial boost and i know how to do it, just
    type in google (with quotes) for – “mundillo traffic increase make your website go viral”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s