DomPDF Library using Codeigniter 3

In this tutorial, we will discuss how to generate PDF using DOMPDF with Codeigniter Framework version 3 and composer(PHP dependency manager).

From the authors of Dompdf –
Dompdf is an HTML to PDF converter. At its heart, DomPDF is (mostly) CSS 2.1 compliant HTML layout and rendering engine written in PHP. It is a style-driven renderer: it will download and read external stylesheets, inline style tags, and the style attributes of individual HTML elements. It also supports most presentational HTML attributes.

DomPDF Library using Codeigniter 3

Dompdf Features:

  • Handles most CSS 2.1 and a few CSS3 properties, including @import, @media & @page rules
  • Supports most presentational HTML 4.0 attributes
  • Supports external stylesheets, either local or through http/ftp (via fopen-wrappers)
  • Supports complex tables, including row & column spans, separate & collapsed border models, individual cell styling
  • Image support (gif, png (8, 24 and 32 bit with alpha channel), bmp & jpeg)
  • No dependencies on external PDF libraries, thanks to the R&OS PDF class
  • Inline PHP support
  • Basic SVG support

Dompdf Requirements

  • PHP version 5.3.0 or higher
  • DOM extension
  • GD extension
  • MBString extension
  • php-font-lib
  • php-svg-lib

This tutorial assuming –
1. you have already installed working CodeIgniter application.
2. Basic knowledge of CodeIgniter and composer.

To install DomPDF with Composer, simply require the latest version of this package as shown below from your project root folder where composer.json reside.

Now enable composer auto loading by making changes to config.php file. Default value was FALSE change it to TRUE.

Wow! everything is ready. As we completed required installation steps, now you can use DomPDF in your controllers like below shown.

Here “index” function of “Welcome” controller will generate pdf file of “welcome_message.php “view file.

By Arjun

I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.

19 replies on “DomPDF Library using Codeigniter 3”

Hi. Thanks for the code. Class dompdf not found in your demo files. I search locally in application/libraries, third_party etc, checking what’s difference between your code and mine. Can you please show how to do this without help of composer? I already have the classes via manual download and even via composer in my local engine. Thanks in advance.

You have to install composer into you ci application folder.Command is composer init.After That you have to write composer require dompdf/dompdf in cmd to the root of application folder and it will work..

Leave a Reply

Your email address will not be published. Required fields are marked *