I am using the Mpdf in symfony. I have installed the mpdf through composer like:
composer require mpdf/mpdf
After that require the Mpdf.php in autoload.php
.
Then use the code for mpdf is:
$mpdf = new mPDF();
$html = '<p style="color:red;">PDF Generating...</p>';
$mpdf->SetDisplayMode('fullpage');
$mpdf->WriteHTML($html);
$mpdf->Output('demo.pdf', 'F');
CSS is not affecting on the HTML. When I'm using the style on tag then it's working fine.
$mpdf = new mPDF();
$html = '<style>p{color:red;}</style><p>PDF Generating...</p>';
$mpdf->SetDisplayMode('fullpage');
$mpdf->WriteHTML($html);
$mpdf->Output('demo.pdf', 'F');
When I try to use the CSS with class or ID then also not affecting.
$mpdf = new mPDF();
$html = '<style>p.text-color{color:red;}</style><p class="text-color">PDF Generating...</p>';
$mpdf->SetDisplayMode('fullpage');
$mpdf->WriteHTML($html);
$mpdf->Output('demo.pdf', 'F');
You don't need the style tag you can do it as follow:
$stylesheet = file_get_contents('style.css');
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($html,2);
So write your CSS first then your html that was working for me the last time.