如何避免wkhtmltopdf表格行内的分页符 [英] How to avoid page break inside table row for wkhtmltopdf

查看:32
本文介绍了如何避免wkhtmltopdf表格行内的分页符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从带有一张表格的 html 页面生成 pdf 报告.

I am generating pdf report from html page with one table.

为此目的,我使用了 wkhtmltopdf.

I am using wkhtmltopdf for the purpose.

当生成 pdf 时,它在 tr 标签中的任何位置中断.

when pdf is generated it breaks anywhere in tr tag.

我想避免它.

推荐答案

更新 17.09.2015: 检查您使用的版本:wkhtmltopdf 0.12.2.4 据说可以解决这个问题(我没有检查过).

Update 17.09.2015: Check the version you are using: wkhtmltopdf 0.12.2.4 is said to fix the problem (I have not checked).

这是 wkhtmltopdf 中的一个已知问题.webkit 使用的分页算法(WKhtmltopdf 中的 WK)对于大型表格并不是很有效.我建议将表格分解为更容易拆分为页面并大量使用 css 的小块:

This is a known issue in wkhtmltopdf. The page breaking algorithm used by webkit (the WK in WKhtmltopdf) doesn't really work well for large tables. I suggest breaking the table down to smaller chunks that are more easily split to pages and using the css a lot:

table, tr, td, th, tbody, thead, tfoot {
    page-break-inside: avoid !important;
}

也看看下面的 wkhtmltopdf 问题,他们有有趣的评论,讨论例如表格拆分问题.有一个 JS 解决方案可以以编程方式将表拆分为 168 位,这可能对您有所帮助(虽然我不使用它).

Also have a look at the following wkhtmltopdf issues, they have interesting comments that discuss for example the table splitting problem. There is a JS solution that programmatically splits tables in 168 that might help you (I don't use it though).

2013 年 11 月 8 日更新上面链接的第 168 期对此有很多讨论.有人设法编译了一个支持更好断表的 wkhtmltopdf 版本,但不幸的是,它似乎没有正式发布,可能包含其他错误.我不知道如何获得它,也不知道如何在 Windows 上编译,但任何有兴趣的人都可以查看例如评论 此处(请参阅下面的新更新).

Update 08.11.2013 There is much discussion about this in issue 168 linked above. Someone has managed to compile a version of wkhtmltopdf that supports better table breaking, but unfortunately it seems that it's not officially released and might contain other bugs. I don't know how to get it and I don't know how to compile on Windows, but anyone interested can check for example the comment here (see new update below).

2014 年 2 月 24 日更新您会很高兴听到在 wkhtmltopdf 0.12 中,此功能得到了极大的改进.但是,在开始使用任何新版本之前,请等待 0.12.1 并进行彻底的测试,尽管使用 antialize 的新人做得很好(ashkulz 岩石),但它仍然有点不稳定!在 wkhtmltopdf.orggithub.谷歌代码站点已过时,正在缓慢迁移.

Update 24.02.2014 You will be pleased to hear that in wkhtmltopdf 0.12 this feature among others has been greatly improved. However, wait for 0.12.1 and test thoroughly before starting to use any new version, it's still a little unstable although the new guys working on with antialize are doing a Great job (ashkulz rocks)! Keep updated at wkhtmltopdf.org and github. The google code site is obsolete and being slowly migrate.

这篇关于如何避免wkhtmltopdf表格行内的分页符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆