External css not working while using dompdf in codeigniter External css not working while using dompdf in codeigniter codeigniter codeigniter

External css not working while using dompdf in codeigniter


DomPDF requires the use of absolute paths for anything you are including.

Thus, you need to use the $_SERVER['DOCUMENT_ROOT'] variable and trail it with the rest of the server path that leads to the file, e.g. $_SERVER['DOCUMENT_ROOT'].'assets/plugins/bootstrap/css/bootstrap.css';

Word of warning:DomPDF's performance decreases radically when embedding large CSS files such as bootstrap (You're looking at a couple of seconds to generate a simple 2-3 page PDF file even if you don't use a lot of formatting). My suggestion would be to inline the specific styles you need in the view rather than linking the full bootstrap library to allow faster dompdf rendering.I faced this very issue some time ago and posted a question (and answer) here, after I did a lot of research, hoping it might help someone else in the future. I recommend reading Slow PDF generation with PHP+DomPDF


You can use the isRemoteEnabled = false property when you create you DomPdf object

$dompdf = new \Dompdf\Dompdf(['isRemoteEnabled' => true]);

You can read in DomPdf github the Options.php file about this option. If isRemoteEnabled is set to true, DOMPDF will access remote sites for images and CSS files as required.

Another option is to include your css styles in your view with an tag.