我们在一个Java应用程序中嵌入了wkhtmltopdf(0.12.1),使用stdin和stdout进行输入/输出.我们想要在PDF中使用多个(不同的)标题,因此我们不会使用--header-html我们使用的选项thead,而是在多个页面上重复使用.这是HTML的一个小例子:
<!DOCTYPE html>
<html>
<body>
<table style="page-break-after: always;">
<thead>
<tr>
<th>My first header</th>
</tr>
</thead>
<tbody>
<tr>
<td>First content</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>My second header</th>
</tr>
</thead>
<tbody>
<tr>
<td>Second content</td>
</tr>
</tbody>
</table>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.当内容跨越多个页面时出现问题.然后标题显示在内容的顶部,与其重叠.示例html和PDF.请注意,第二个标题渲染得很好,因为tr它只覆盖一页.
其他人也遇到过类似的问题.当您使用该--header-html选项时,有一些解决方法,例如添加--header-spacing或--margin-top,但这些选项对重复没有影响thead.有任何想法吗?
Jua*_*lez 39
我用这三个css规则解决了它:
thead { display: table-header-group; }
tfoot { display: table-row-group; }
tr { page-break-inside: avoid; }
Run Code Online (Sandbox Code Playgroud)
我发现tr { page-break-inside: avoid; }工作到了一定程度,但当我的标题跨越多行时就不行了。由于我想保留我的thead部分,我的解决方案是关闭重复。
thead, tfoot {
display: table-row-group;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13365 次 |
| 最近记录: |