$pdf = new Pdf([
// set to use core fonts only
'mode' => Pdf::MODE_CORE,
// A4 paper format
'format' => Pdf::FORMAT_A4,
// portrait orientation
'orientation' => Pdf::ORIENT_PORTRAIT,
// stream to browser inline
'destination' => Pdf::DEST_BROWSER,
// your html content input
'content' => $content,
// format content from your own css file if needed or use the
// enhanced bootstrap css built by Krajee for mPDF formatting
'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
// any css to be embedded if required
'cssInline' => '.kv-heading-1{font-size:18mm}',
// set mPDF properties on the fly
'options' => ['title' => 'Title'],
// call mPDF methods on the fly
'methods' => [
// 'SetHeader'=>['Krajee Report Header'],
// 'SetFooter'=>['{PAGENO}'],
],
'marginTop' => 1,
'marginBottom' => 1,
'marginLeft' => 2,
'marginRight' => 0,
]);
HTML:
$html = '<style>'. $mystyle .' </style>';
$html .= '<div>' . $mydiv . '</div>';
echo $html;
尝试使用内部样式打印div,但即使显示div,内部样式似乎也不起作用。没有显示错误,所以它是否有可能不支持内部风格?或者我错过了什么?
**内联样式正在运作
答案 0 :(得分:1)
我发现内部风格不起作用的答案是因为我传递给PDF的内容被解读为“内容”。我需要将样式传递给'cssInline'而不是'content'。