智能 html 分页符
我制作 html 报告并打印它们(或 PDF),并希望进行智能分页符。我想避免标题位于一页上而段落位于下一页上。在这种情况下,下一页应该从标题开始。
我尝试过 page-break-after:avoid 但没有成功。我不明白为什么。如果我尝试 page-break-after:always
它会起作用。所以我猜避免功能不是那么好。我一直用IE8。
他们有任何脚本方法来计算分页符应该在哪里吗?如果是的话,我可以在那个地方做一个 page-break-after:always
。
谢谢! /乔治
I make html reports and print them (or PDF) and want to make smart page breaks. I want to avoid that the heading is on one page and the paragraph on the next page. In that case the next page should start with the heading.
I have tried page-break-after:avoid
but with no success. And I don't understand why. If I try page-break-after:always
it works. So I guess the avoid functions is not that good. I always use IE8.
Is their any script way to calculate where the page break should be? If their is I can just make a page-break-after:always
at that place.
Thanks!
/Georg
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个类只是一个提示。只有在可以避免的情况下才可以避免分页符。如果这意味着必须剪切结果,那么毕竟会插入分页符。
我认为不可能计算分页符的位置,因为它取决于许多变量,包括打印机边距和纸张尺寸,这些变量在 CSS 或 JavaScript 中都无法访问。
This class is only a hint. A page break is only avoided if it can be avoided. If it would mean the result would have to be clipped, a page break will be inserted after all.
I don't think it's possible to calculate where the page breaks would be, because it depends on numerous variables, including printer margins and paper size, which are not accessable in CSS nor JavaScript.
我使用 TCPDF (http://www.tcpdf.org/) 来做类似的事情。尽管它正在打印表格数据,但很容易将分页符放在正确的位置,这样我就可以进行行计数。
您可以尝试使用字符计数,但它不会那么准确。
I used TCPDF (http://www.tcpdf.org/) to do something similar. It was easy to get the page breaks in the right place though as it was printing tabular data so I could do a row count.
You could try it with a character count but it wouldn't be as accurate.