wkhtmltopdf 0.12.6版本处理表格时分页失效问题求助
wkhtmltopdf 0.12.6 表格tbody分页失效问题
从Stack Overflow的多版本相关问答来看,wkhtmltopdf在处理表格分页时存在兼容问题。我当前使用的是撰写时的最新版本0.12.6。
我的HTML代码如下:
<HTML> <head> <title>A nice page</title> <link rel="stylesheet" href="screen.css" media="screen" /> <link rel="stylesheet" href="printer.css" media="print" /> </head> <body> <table class="printer_friendly"> <tbody class="printer_friendly_tbody"> <tr> <td class="tbody_first" colspan="6">This is the beginning of a new picture. This must be the first in the groupof tbody 0</td> </tr> <tr> <th colspan="3.0" rowspan="5"> <img src="images/pdf_download.png" width="300px" /> </th> <td>Random text</td> <td>Random text</td> <td>Random text</td> </tr> <tr> <td>This is (0, 0) in tbody 0</td> <td>This is (0, 1) in tbody 0</td> <td>This is (0, 2) in tbody 0</td> </tr> <tr> <td>This is (1, 0) in tbody 0</td> <td>This is (1, 1) in tbody 0</td> <td>This is (1, 2) in tbody 0</td> </tr> <tr> <td>This is (2, 0) in tbody 0</td> <td>This is (2, 1) in tbody 0</td> <td>This is (2, 2) in tbody 0</td> </tr> <tr> <td>This is (3, 0) in tbody 0</td> <td>This is (3, 1) in tbody 0</td> <td>This is (3, 2) in tbody 0</td> </tr> <tr> <td colspan="6">This is (0, 2) in tbody 0</td> </tr> <tr> <td colspan="6">This is (1, 2) in tbody 0</td> </tr> </tbody> <tbody class="printer_friendly_tbody"> <tr> <td class="tbody_first" colspan="6">This is the beginning of a new picture. This must be the first in the groupof tbody 1</td> </tr> <tr> <th colspan="3.0" rowspan="5"> <img src="images/pdf_download.png" width="300px" /> </th> <td>Random text</td> <td>Random text</td> <td>Random text</td> </tr> <tr> <td>This is (0, 0) in tbody 1</td> <td>This is (0, 1) in tbody 1</td> <td>This is (0, 2) in tbody 1</td> </tr> <tr> <td>This is (1, 0) in tbody 1</td> <td>This is (1, 1) in tbody 1</td> <td>This is (1, 2) in tbody 1</td> </tr> <tr> <td>This is (2, 0) in tbody 1</td> <td>This is (2, 1) in tbody 1</td> <td>This is (2, 2) in tbody 1</td> </tr> <tr> <td>This is (3, 0) in tbody 1</td> <td>This is (3, 1) in tbody 1</td> <td>This is (3, 2) in tbody 1</td> </tr> <tr> <td colspan="6">This is (0, 2) in tbody 1</td> </tr> <tr> <td colspan="6">This is (1, 2) in tbody 1</td> </tr> </tbody> </table> </body> </html>
根据Stack Overflow的建议,我把需要保持在一起的行分组到tbody中,并为打印媒体设置了如下CSS:
.printer_friendly_tbody { background-color:aliceblue; page-break-inside:avoid; page-break-before:auto; page-break-after:auto; }
我的需求是让每个tbody内的所有行保持在一起,必要时在.printer_friendly_tbody之前或之后拆分表格。用Chrome的打印/生成PDF功能可以得到完美的结果,但用wkhtmltopdf生成时完全失效。我已经尝试过启用和禁用打印媒体选项,但都没用。因为必须用到wkhtmltopdf的其他功能,所以希望能找到解决这个问题的方法,求建议?
内容的提问来源于stack exchange,提问作者toto
相关产品推荐
相关产品推荐

