CodeIgniter Forums
Integrating dompdf - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Addins (https://forum.codeigniter.com/forumdisplay.php?fid=34)
+--- Thread: Integrating dompdf (/showthread.php?tid=76319)



Integrating dompdf - rmilecki - 05-03-2020

I want to try using dompdf for generating PDFs. It's simpler than TCPDF and wkhtmltopdf so a good choice for me if it works good enough.

I downloaded it to app/ThirdParty/ and in Autoload.php I added it to $psr4:
PHP Code:
$psr4 = [
    
'App'         => APPPATH,                // To ensure filters, etc still found,
    
APP_NAMESPACE => APPPATH,                // For custom namespace
    
'Config'      => APPPATH 'Config',
    
'Dompdf'      => APPPATH 'ThirdParty/dompdf/src',
]; 

Trying to use it:
PHP Code:
$dompdf = new \Dompdf\Dompdf(); 

results in error though:
Code:
Class 'Dompdf\Cpdf' not found


It seems that dompdf has its own Autoloader.php which has some magic code for handling Dompdf\Cpdf:
https://github.com/dompdf/dompdf/blob/master/src/Autoloader.php
but it doesn't work with CodeIgniter 4.

Any hint how to fix that? I don't like using
PHP Code:
require_once APPPATH 'ThirdParty' DIRECTORY_SEPARATOR 'dompdf' DIRECTORY_SEPARATOR 'autoload.inc.php'



RE: Integrating dompdf - jreklund - 05-03-2020

Don't know if this is possible, but you can at least try. Personally I would use it the Composer way. :-)

PHP Code:
$psr4 = [
    
'App'         => APPPATH,                // To ensure filters, etc still found,
    
APP_NAMESPACE => APPPATH,                // For custom namespace
    
'Config'      => APPPATH 'Config',
    
'Dompdf\\Dompdf'      => APPPATH 'ThirdParty/dompdf/src',
    
'Dompdf\\Cpdf'      => APPPATH 'ThirdParty/dompdf/lib',
]; 



RE: Integrating dompdf - owino - 04-17-2021

I had similar problem... see my experience and solution.


RE: Integrating dompdf - abatrans - 04-18-2021

I would suggest you look at MPDF (get it via composer.

Very easy to setup and use. In my opinion the best pdf library as it support html and css.


RE: Integrating dompdf - kenjis - 12-01-2023

If you use Composer, you don't need to add autoloader config manually.
This code worked in my environment.
https://forum.codeigniter.com/showthread.php?tid=82461&pid=414111#pid414111