我正在尝试转换我的html页面到pdf格式使用mpdf.问题是,我无法应用一个以上的css到pdf文件..这里是我的代码的php
<?php
$html =file_get_contents('mpdf/test.html');
include("../mpdf.php");
$mpdf=new mPDF();
$mpdf->SetDisplayMode('fullpage','two');
// LOAD a stylesheet 1
$stylesheet = file_get_contents('assets/css/main.css');
$mpdf->WriteHTML($stylesheet,1); // The parameter 1 tells that this is css/style only and no body/html/text
// LOAD a stylesheet 2
$stylesheetextra = file_get_contents('assets/css/test.css');
$mpdf->WriteHTML($stylesheetextra ,1); // The parameter 1 tells that this is css/style only and no body/html/text
$mpdf->WriteHTML($html,2);
$mpdf->Output();
exit;
?>
它给出的输出不附带test.css。main.css是正确应用到pdf文件,但test.css不适用。请帮助我?提前感谢您
3条答案
按热度按时间thigvfpy1#
只需将CSS内容存储在一个变量中即可,如下所示:
x6h2sr282#
这可能是一个丑陋的解决方案,但我以前遇到过类似的问题。我所做的是,因为这不是一个大问题,我把所有的css从第二个我不能添加,并添加到“main.css”。
ux6nzvsh3#
(mPDF ≥ 1.0)
使用\Mpdf\HTMLParserMode::HEADER_CSS作为第二个参数。
链接origin