如何避免跨页面拆分HTML表

时间:2016-01-31 05:15:04

标签: html css pdf-generation wkhtmltopdf dompdf

请原谅我的英语。

我正在以pdf格式打印一份大型报告,包括一些表格(一桌一桌)。为此,我首先使用html生成报告,然后使用dompdf将其传递给pdf

这是我一个接一个地打印一张桌子的方式:

A
--------------
id  | aa
--------------
1   | 3.4
2   | 4.5
3   | 5.5
--------------

B
--------------
id | A_id | bb
--------------
1  | 2    | [{"d":"ddd", "e":"eee"}, {"d":"dqdq", "e":"eqeq"}]
2  | 1    | [{"d":"fff", "e":"ggg"}, {"d":"hhh", "e":"iii"}]
3  | 3    | [{"d":"ddd", "e":"jjj"}, {"d":"kkk", "e":"lll"}]
--------------

**After GROUP BY:**

"ddd" => [{A_id: 2, A.aa: 4.5}, {A_id: 3, A.aa: 5.5}],
"fff" => [{A_id: 1, A.aa: 3,4}]

Desired Outcome:
A
--------
id  | aa
--------
2   | 4.5
1   | 3.4

This is the way in which printed tables when there is a page break

问题是当存在分页符时,表行被拆分。我想避免它。

我尝试使用CSS打印属性,但它不起作用,在其他情况下,<div> <table> ----- </table> </div> <div> <table> ----- </table> </div> 在不同的页面上打印报表的每个表格。

page-break-before: always;

我只能在必要时在报告的所有表格中强制分页。

请帮忙。

2 个答案:

答案 0 :(得分:2)

检查此链接: Link1 {
{3}} {
{3}}

有很多与你的问题相关的答案,所以首先尝试这个答案。 您可以尝试使用CSS:

<table class="print-friendly">
 <!-- The rest of your table here -->
</table>

<style>
    table.print-friendly tr td, table.print-friendly tr th {
        page-break-inside: avoid;
    }
</style>

大多数CSS规则不直接适用于<tr>标记,因为您完全按照上面的指示 - 它们具有唯一的display样式,不允许使用这些CSS规则。但是,其中的<td><th>标记通常执行允许此类规范 - 您可以轻松地将此类规则应用于所有子级 - <tr>并且<td>使用CSS,如上所示。

答案 1 :(得分:0)

@ sebastianpe93尝试在打印媒体查询中添加样式。这应该工作

相关问题