简体   繁体   English

智能html分页符

[英]Smart html page break

I make html reports and print them (or PDF) and want to make smart page breaks. 我制作HTML报告并打印它们(或PDF)并希望制作智能分页符。 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. 我试过了page-break-after:avoid但没有成功。 And I don't understand why. 我不明白为什么。 If I try page-break-after:always it works. 如果我尝试page-break-after:always有效。 So I guess the avoid functions is not that good. 所以我猜避免功能并不是那么好。 I always use IE8. 我总是使用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. 如果他们是我可以做一个page-break-after:always在那个地方。

Thanks! 谢谢! /Georg /格奥尔格

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. 我不认为可以计算分页的位置,因为它取决于许多变量,包括打印机边距和纸张大小,这些变量在CSS和JavaScript中都不可访问。

I used TCPDF (http://www.tcpdf.org/) to do something similar. 我使用TCPDF(http://www.tcpdf.org/)做类似的事情。 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. 您可以尝试使用字符计数,但它不会那么准确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM