DOMPDF doesn't work with external css file
This has in fact nothing to do with Zend Framework, but you need to supply DomPDF the right path to load the "external" files from.
$dompdf = new DOMPDF();
$dompdf->setBasePath(realpath(APPLICATION_PATH . '/path/to/css/'));
$dompdf->loadHtml($html);
$dompdf->render();
See also the manual of DomPDF for this feature.
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
DOMPDF doesn't work with external css file
This has in fact nothing to do with Zend Framework, but you need to supply DomPDF the right path to load the "external" files from.
$dompdf = new DOMPDF();
$dompdf->setBasePath(realpath(APPLICATION_PATH . '/path/to/css/'));
$dompdf->loadHtml($html);
$dompdf->render();
See also the manual of DomPDF for this feature.
Add CSS to DomPDF
the css file must be referenced in the HTML you give to DomPDF.
If you don't want to change your twig template, you can use a workaround like this :
$dompdf = new Dompdf();
$html = $this->renderView('dashboard/user_table.html.twig', [
'users' => $users
]);
$html .= '<link type="text/css" href="/absolute/path/to/pdf.css" rel="stylesheet" />';
$dompdf->loadHtml($html);
Note that adding a link
tag to the body is not valid according to HTML specifications. With the current Dompdf version, it works but it may not work in future versions.
CSS not working with DOMPDF
dompdf v0.5.x does not support floats. v0.6.0 does, though it is still an experimental feature that has to be enabled in the configuration. After testing your document I can say that dompdf doesn't handle it very well. If you want to stick with dompdf you might consider tables since your document is somewhat tabular in nature.
Dompdf 0.8.3 not fetching remote CSS in PHP 7.2 and CodeIgniter 3
The problem was due to a port redirection issue in the server. Solved :) Thank you all!
Related Topics
How to Center Block of Inline-Blocks
Highcharts Graph Width Is Incorrect When Scrollbar Is Present, in Bootstrap Fluid Span
How to Collapse Unused Row in a CSS Grid
How to Change Md-Input-Container Placeholder Color Using CSS in Angular Material
Change the Style of an Element If the Fragment Identifier (Hash) in the Url References It
Centering the Navbar Content in Bootstrap 4 (Alpha 5)
Bootstrap 4 - No Column Wrapping
CSS - Is There a Cousin Selector
Are "Top" and "To Top" the Same Direction for Linear Gradients
<!--[If Ie]> Conditional Comments Are Rendered HTML-Escaped in Facelets
Change the State According to Event in Reactjs
CSS :Not(:Last-Child):After Selector
Difference Between CSS3 Transitions' Ease-In and Ease-Out
Position Last Flex Item at the End of Container