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.

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.

0 0 vote
Article Rating
Subscribe
Notify of
guest
19 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Shany Mathew
Shany Mathew
4 years ago

Good

rikynurdiana
rikynurdiana
3 years ago

Class ‘DompdfDompdf’ not found

how to fix this?

arjun
2 years ago
Reply to  rikynurdiana

you can download the demo and try …

rikynurdiana
rikynurdiana
2 years ago
Reply to  arjun

thanks. you save my time

chandan
chandan
2 years ago
Reply to  arjun

In your demo i also got same issue class ‘DompdfDompdf ‘ not found

Deepak Prasad
Deepak Prasad
2 years ago

Class ‘DompdfDompdf’ not found

arjun
2 years ago
Reply to  Deepak Prasad

you can download the demo and try … if you still need my help let me know.

Hpesoj Nosliw
Hpesoj Nosliw
2 years ago

Class ‘DompdfDompdf’ not found in demo code

arjun
2 years ago
Reply to  Hpesoj Nosliw

After downloading, you have to run composer install command, it will pull the library to your project.

gopal venu
gopal venu
2 years ago

Class ‘DompdfDompdf’ not found. I have also installed dompdf with composer. Still this problem shows

arjun
2 years ago
Reply to  gopal venu

Did make changes to $[‘composer_autoload’] value? Are you able to see vendor directory after composer install?

gopal venu
gopal venu
2 years ago
Reply to  arjun

yes i have changed $[‘composer_autoload’] to true. There are also vendor directory in the root directory

arjun
2 years ago
Reply to  gopal venu

hmm.. it should work, I just downloaded demo files and tried its working..

arjun
2 years ago
Reply to  arjun

Let me know your PHP version and CI version I will try.

za
za
2 years ago

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.

Kiran Chowdary
Kiran Chowdary
2 years ago

Class ‘DompdfDompdf’ not found.i have installed dompdf composer.json

Koushik Dutta
Koushik Dutta
8 months ago
Reply to  Kiran Chowdary

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..

arjun
2 years ago

Please share your environment details, so that I can provide solution

Koushik Dutta
Koushik Dutta
8 months ago

Thanks Man

DMCA.com Protection Status
19
0
Would love your thoughts, please comment.x
()
x