【问题标题】:how to add multiple css file in mpdf如何在mpdf中添加多个css文件
【发布时间】:2015-12-26 15:41:41
【问题描述】:

我正在尝试使用 mpdf 将我的 html 页面转换为 pdf 格式。问题是我无法将多个 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 没有应用。请 帮我? 提前谢谢你

【问题讨论】:

  • 确实将第二个样式表附加到第一个工作,即 $stylesheet = file_get_contents('assets/css/main.css') 。 file_get_contents('assets/css/test.css'); $mpdf->WriteHTML($stylesheet,1);

标签: php html css mpdf


【解决方案1】:

您可以将 CSS 内容存储在一个变量中,如下所示:

$stylesheet  = '';
$stylesheet .= file_get_contents('css/bootstrap.min.css');
$stylesheet .= file_get_contents('css/style.css');
$stylesheet .= file_get_contents('css/impressao_ctr.css');

【讨论】:

    【解决方案2】:

    这可能是一个丑陋的解决方案,但我之前遇到过类似的问题。我所做的是,因为这不是一个大问题,所以我从第二个我无法添加的 css 中取出所有 css,并将其添加到“main.css”中。

    【讨论】:

    • 您找到更好的解决方案了吗?
    猜你喜欢
    • 2013-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-09
    • 1970-01-01
    • 2018-07-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多