使用 MPDF 在每一页上的表格标题

问题描述

我希望在使用 MPDF 库生成 pdf 时在每一页上显示表格标题

$mpdf = new \Mpdf\Mpdf([
'mode'=>'utf-8','format' => 'A4-L'
]);

$mpdf->SetHTMLHeader("<table>
                    <tr>
                          <th>Sl No.</th>
                          <th>Name</th> 
                    </tr>
");

for($i=0; $i<500;$i++){
      $mpdf->WriteHTML("<tr>");
      $mpdf->WriteHTML("<td>".$res[$i]["slno"]."</td>");
      $mpdf->WriteHTML("<td>".$res[$i]["name"]."</td>");
      $mpdf->WriteHTML("</tr>");                       
                       
                   
}
      $mpdf->WriteHTML("</table>");

解决方法

只需使用 <thead> 标签。页眉外。

$mpdf->WriteHTML('

<table>
<thead>
    <tr>
        <th>Sl No.</th>
        <th>Name</th> 
    </tr>
<thead>

...');

https://mpdf.github.io/tables/tables.html#repeating-table-header-row-on-new-page