Posted on Updated on - Arjun

DomPDF Library using Codeigniter 3

In this tutorial we will discus about 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 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 CodeIngiter application.
2. Basic knowledge of CodeIngiter 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! every thing 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.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

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

    Good

  • rikynurdiana

    Class ‘DompdfDompdf’ not found

    how to fix this?

DMCA.com Protection Status