php - Mpdf用样式表生成空白pdf
问题描述
Mpdf 在包含样式表时生成空白白页 pdf,当我删除样式表时工作正常$mpdf->WriteHTML($stylesheet,1);
但我想包含样式表。任何帮助表示赞赏。
<?php
if(isset($_POST['pdf'])){
ob_clean();
flush();
/*-------------------- for genearte pdf start -----------------*/
include("mpdf/vendor/autoload.php");
include('includes/db.php');
$mpdf = new \Mpdf\Mpdf();
//$html = '<h1>Welcome</h1>';
$html = '<div class="table-responsive">
<table class="table table-hover tablesorter pdf_border">
<thead>
<tr class="pdf_border">
<th class="header pdf_border">Name</th>
</tr>
</thead>
<tbody>'; ?>
<?php
$sqli = "SELECT * FROM user";
$resulti = mysqli_query($connection,$sqli);
while($row = mysqli_fetch_assoc($resulti))
{
$html .= '<tr class="pdf_border">
<td class="pdf_border">'.$row['name'].'</td>
</tr>';
}
$html .= '</tbody></table>';
$path = 'pdf/';
$file_name ="webpreparations-".time().".pdf";
$stylesheet =file_get_contents('css/bootstrap.min.css');
$mpdf->WriteHTML($stylesheet,1); //
$mpdf->WriteHTML($html,2);
$mpdf->Output($path.$file_name, "D");
}
?>
<form action="" method="post">
<input type="submit" name="pdf" class="pull-right btn btn-warning btn-large" style="margin-right:40px" value="Genarte PDF">
</form>
如果我删除,则会损坏 pdf 文件ob_clean(); flush();
解决方案
使用添加样式表
$mpdf->WriteHTML('path/your stylsheet.css'), \Mpdf\HTMLParserMode::HEADER_CSS);
推荐阅读
- php - CodeIgniter 3 会话不适用于我的所有用户
- visual-studio - 当我构建我的项目时,需要花费大量时间来编译
- python - 对行之间的某些值求和
- python - 使用 Pandas 在巨大的 CSV 中解析带有嵌套值的 JSON 列
- javascript - 如何传递一个跨度值 VUE
- android - 如何在 Nougat 中为 ACTION_VIEW 使用内容 URI?
- xamarin.forms - Xamarin.Forms 中用于 .Net Standard 2.0 的 ModernHttpClient
- ssl - 如何在kong中为API配置ssl
- bigcommerce - 如何在模板中获取 base_url
- javascript - 从后端强制登录 401 后做出反应