怎么做
<tr>
<th>a</th>
<th>b</th>
<th>c</th>
<th>d</th>
<th>e</th>
</tr>
Run Code Online (Sandbox Code Playgroud)
始终可在每页上打印.
我的看法
<style>
@page { margin: 150px 50px; }
#header { position: fixed; left: 0px; top: -100px; right: 0px; height: 50px; text-align: center; }
#footer { position: fixed; left: 0px; bottom: -180px; right: 0px; height: 150px; text-align: center; }
#footer .page:after { content: counter(page, upper-roman); }
</style>
<div id="header">
<h1>Tittle</h1>
</div>
<div id="content">
<?php
echo"<table class='gridtable'>";
?>
<table width="100%" page-break-inside: auto;>
<tr>
<th>a</th>
<th>b</th>
<th>c</th>
<th>d</th>
<th>e</th>
</tr>
<?php
$num = 0;
foreach($result as $key=>$val){
$num++;
echo"<tr>
<td>".$a."</td>".
"<td>".$val['b']."</td>".
"<td>".$val['c']."</td>".
"<td>".$val['d']."</td>".
"<td>".$val['e']."</td>".
"</tr>";
}
?>
</table>
<?php
echo"</table>";
?>
</div>
<script type="text/php">
if ( isset($pdf) ) {
$font = Font_Metrics::get_font("helvetica", "bold");
$pdf->page_text(280, 780, "Page {PAGE_NUM} of {PAGE_COUNT}", $font, 10, array(0,0,0));
}
</script>
Run Code Online (Sandbox Code Playgroud)
例如,下载后,这是我的PDF
第1页:
| Title 1 | Tittle 2 | Tittle 3 |
| row 1 | row 1 | row 1 |
Run Code Online (Sandbox Code Playgroud)
第2页:
| row 2 | row 2 | row 2 |
Run Code Online (Sandbox Code Playgroud)
如何制作第二页这样:
| Title 1 | Tittle 2 | Tittle 3 |
| row 2 | row 2 | row 2 |
Run Code Online (Sandbox Code Playgroud)
我希望Tittle总是印在每一页的顶部.谢谢
在最近的DOMPDF版本中(例如,我相信版本为0.5.2或更高版本),您可以将包含表头的行包装在THEAD中.
将您的观点更改为:
<table width="100%" page-break-inside: auto;>
<thead>
<tr>
<th>a</th>
<th>b</th>
<th>c</th>
<th>d</th>
<th>e</th>
</tr>
<thead>
Run Code Online (Sandbox Code Playgroud)
这应该可以解决问题.有一种情况是它失败了:如果你的表被渲染以便它在你之后thead但在渲染任何数据行之前中断,那么thead它将不会显示在下一页上.如果表格突破了另一个页面,thead则会显示在后续页面上.