首页 > 解决方案 > 表格标题和分页符在 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 页之间拆分

标签: wkhtmltopdf

解决方案


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


推荐阅读