简体   繁体   中英

Smart html page break

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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