我使用此库mikehaertl/phpwkhtmltopdf在PHP中使用wkhtmltopdf。 包含表格并且我正在使用的HTML代码如下:
<!DOCTYPE html>
<html>
<head>
<title>Invoice</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css">
tr{
page-break-inside: avoid;
}
html,body{
height:370mm;
}
</style>
</head>
<body>
<table style="font-size: 14px;text-align: center;height:223mm;width: 100%;border-left: 1px solid #1c2f68;border-right: 1px solid #1c2f68;border-bottom: 1px solid #1c2f68;" cellspacing="0">
<thead>
<tr>
<th style="color: #fff;background-color: #1c2f68;">A</th>
<th style="color: #fff;background-color: #1c2f68;">B</th>
<th style="color: #fff;background-color: #1c2f68;">C</th>
<th style="color: #fff;background-color: #1c2f68;">✓</th>
<th style="color: #fff;background-color: #1c2f68;">D</th>
<th style="color: #fff;background-color: #1c2f68;">E</th>
<th style="color: #fff;background-color: #1c2f68;">F</th>
</tr>
</thead>
<tbody>
<tr style="height:15px">
<td style="font-family: arial;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr>
<tr style="height:30px">
<td style="font-family: arial;">04/09/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 1</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">A</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">00.00</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr style="height:30px">
<td style="font-family: arial;">04/09/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 142 82128</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">B</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">16.00</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr style="height:30px">
<td style="font-family: arial;">04/16/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 142 82303</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">C</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">16.00</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr style="height:30px">
<td style="font-family: arial;">04/16/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 142 82317</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">D</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">16.00</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr style="height:30px">
<td style="font-family: arial;">04/09/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 142 82108</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">E</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">43.42</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr style="height:30px">
<td style="font-family: arial;">04/09/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 142 82128</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">F</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">16.00</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr style="height:30px">
<td style="font-family: arial;">04/16/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 142 82303</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">G</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">16.00</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr style="height:30px">
<td style="font-family: arial;">04/16/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 142 82317</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">H</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">16.00</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr style="height:30px">
<td style="font-family: arial;">04/09/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 142 82108</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">I</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">43.42</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr style="height:30px">
<td style="font-family: arial;">04/09/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 142 82128</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">J</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">16.00</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr style="height:30px">
<td style="font-family: arial;">04/16/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 142 82303</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">K</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">16.00</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr style="height:30px">
<td style="font-family: arial;">04/16/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 142 82317</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">L</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">16.00</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr style="height:30px">
<td style="font-family: arial;">04/09/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 142 82108</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">M</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">43.42</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr style="height:30px">
<td style="font-family: arial;">04/09/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 142 82128</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">N</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">16.00</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr style="height:30px">
<td style="font-family: arial;">04/16/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 142 82303</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">O</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">16.00</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr style="height:30px">
<td style="font-family: arial;">04/16/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 142 82317</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">P</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">16.00</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr style="height:30px">
<td style="font-family: arial;">04/09/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 142 82108</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">Q</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">43.42</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr style="height:30px">
<td style="font-family: arial;">04/09/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 142 82128</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">R</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">16.00</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr style="height:30px">
<td style="font-family: arial;">04/16/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 142 82303</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">S</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">16.00</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr style="height:30px">
<td style="font-family: arial;">04/16/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 142 82317</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">T</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">16.00</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr style="height:30px">
<td style="font-family: arial;">04/09/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 142 82108</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">U</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">43.42</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr style="height:30px">
<td style="font-family: arial;">04/09/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 142 82128</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">V</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">16.00</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr style="height:30px">
<td style="font-family: arial;">04/16/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 142 82303</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">W/td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">16.00</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr style="height:30px">
<td style="font-family: arial;">04/16/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 142 82317</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">X</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">16.00</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr style="height:30px">
<td style="font-family: arial;">04/09/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 142 82108</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">Y</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">43.42</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr style="height:30px">
<td style="font-family: arial;">04/09/18</td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: left;margin-left:15px;">Invoice 142 82128</span></td>
<td style="font-family: arial;border-left: 1px solid #000;">Z</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"><span style="float: right;margin-right:15px;">16.00</span></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr><tr>
<td style="font-family: arial;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr>
<tr style="height:1px">
<td style="font-family: arial;text-align:left;" colspan="2"> xxxxxxxxxxxxxxxxxxxxxxxxxx</td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
<td style="font-family: arial;border-left: 1px solid #000;"></td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>
当我使用下面的代码创建PDF时,因为表格很长,所以在很多页面中分割,我使用page-break-inside:avoid;避免将表格的标题与下一页的第一行混合。那么如何在每页底部添加边框(见附图)? 感谢。
$options = array(
'footer-right' => 'Page [page] of [toPage]',
'footer-font-size' => 8
);
$pdf = new mikehaertl\wkhtmlto\Pdf();
$pdf->addPage($table);//$table holds the HTML code above
$pdf->setOptions($options);
$pdf->binary = 'wkhtmltox_0.12.4/bin/wkhtmltopdf';
$pdf->send("sample.pdf");
}
[1]: https://github.com/mikehaertl/phpwkhtmltopdf