【问题标题】:Internal style not working for my pdf内部样式不适用于我的 pdf
【发布时间】:2016-01-21 12:08:35
【问题描述】:
$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 正在显示。没有显示错误,所以它有没有可能不支持内部样式?还是我错过了什么?

**内联样式有效

【问题讨论】:

    标签: php html css pdf


    【解决方案1】:

    我发现内部样式不起作用的答案是因为我传递给 PDF 的任何内容都被读取为“内容”。我需要将样式传递给“cssInline”而不是“内容”。

    【讨论】:

    • 但无论如何要同时通过 2 个模型?一个用于内容,另一个用于 cssInline
    • 这是一个答案吗?我不认为是
    • @Martin 为什么不呢?我确实解释了为什么它不起作用以及如何使它起作用
    • 我不确定这是一个答案还是问题的延续!感谢您的澄清
    猜你喜欢
    • 2021-09-17
    • 2018-09-26
    • 2018-07-08
    • 2021-04-13
    • 2021-01-19
    • 1970-01-01
    • 2014-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多