简体   繁体   中英

Include stylesheet file into MPDF conversion in PHP

I have made HTML to convert it into PDF using MPDF, but issue is that I can't include a stylesheet file.

Example:

include("../mpdf.php");
$mpdf=new mPDF('c'); 
$mpdf->SetDisplayMode('fullpage');
// LOAD a stylesheet
$stylesheet = file_get_contents('mpdfstyleA4.css');
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($html);
$mpdf->Output();

I used the code above but I can't see the effect of the styles. Does anyone know a better way to include styles?

You need to load the stylesheet in the html - it's not clear in your snippet where the content for $html comes from but that's the place to load styles. Using your code you'll be writing the CSS you've loaded as if it were document content for the PDF, which I assume isn't your intent.

It looks to me you are setting the new PDF function into "Code" mode. $mpdf=new mPDF('c');

Have you tried it without the "C"?

$mpdf=new mPDF();

Also, is your stylesheet, "mpdfstyleA4.css", located in the same path as mpdf.php?

mPdf works best with inline style sheets which cause no bugs while pdf opens in different browsers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM