wkhtmltopdf - 表格标题和分页符在 wkhtmltopdf 中不起作用
问题描述
我在 Debian Buster 上使用 wkhtmltopdf 版本 0.12.5。我无法让它使用 CSS 声明执行以下任何控制表格显示和分页的行为:
- 在每页顶部打印表格标题
- 控制页面方向(设置为横向)
- 插入分页符
我正在使用的生产表非常高(100 行),我需要在每一页的顶部打印表头。我还想避免在一排中间打断。
我已经成功地让它在表格的末尾添加了一个分页符,我可以在命令行上指定页面方向,但是我需要在实际文档上使用 CSS(样式表或内联很好)来控制所有这些行为.
示例代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test Page</title>
<style type="text/css">
thead { display: table-header-group }
tfoot { display: table-row-group }
tr { page-break-inside: avoid }
</style>
</head>
<body>
<h1>Title Here</h1>
<div>
<span id="filterModeLabel" class="FilterMode">Show all</span>
<table>
<thead>
<tr><th>FirstName</th><th>LastName</th></tr>
</thead>
<tbody>
<tr><td>John</td><td>Smith</td></tr>
<tr><td>John</td><td>Smith</td></tr>
<!-- Enough lines to push it onto two pages -->
<tr><td>John</td><td>Smith</td></tr>
<tr><td>John</td><td>Smith</td></tr>
</tbody>
</table>
</div>
</body>
</html>
我还尝试了以下样式表变体,但没有运气:
@page {
size: letter;
size: landscape;
margin-top: .40in;
margin-left: .40in;
margin-right: .40in;
margin-bottom: .25in;
font-size: 10px;
@bottom-right { content: "Page " counter(page) " of " counter(pages)};
}
thead{
display: table-header-group
}
tfoot {
display: table-row-group
}
tr {
page-break-inside: avoid
}
table {
page-break-inside:auto;
word-wrap: break-word;
page-break-after: always;
border-collapse:collapse;
}
table tbody tr{
page-break-inside:avoid;
}
table.standard thead {
display:table-header-group;
font-size: 12px;
}
table tfoot { display: table-row-group; }
table tbody tr td
,table thead tr th {
font-size: 12px;
line-height: 10pt;
border: 1px solid black;
}
这是我在命令行上运行的调用:
wkhtmltopdf p1.html p1a.pdf
这是我得到的结果的屏幕截图(第 1 页和第 2 页的顶部): 第 1 页的顶部 在第 1 页和第 2 页之间拆分
解决方案
debian buster 安装没有修补 QT 这解决了我的问题。
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.buster_amd64.deb apt install ./wkhtmltox_0.12.6-1.buster_amd64.deb
推荐阅读
- image - 如何将我的图像矢量大小从 64,128 转换为 64*128 的矢量
- ios - Swift 3.0 不受支持,即使项目设置为 Swift 5
- php - Dropbox API cURL 请求错误:“选项:预期数组,得到字符串”
- excel - 具有条件的工作表列表中的几次 Excel 平均值
- javascript - 当用户在输入字段中输入值时,使用 javascript 格式化输入值
- vue.js - 计算属性的返回值在模板中使用时不会改变(没有组合 API 的 Vue3)
- matlab - 如何将unnest单元阵列更改为排队的阵型?
- javascript - 表格没有在 jQuery 中动态附加
- azure - Azure 内部负载均衡器能否拥有属于 VNET 中不同子网的后端?
- sql - 执行 INSERT INTO 与使用 MERGE INTO 之间的区别