Finding out where the browser will insert page breaks when printing

I am trying to figure out where a browser, in particular firefox or chrome, will insert page breaks when printing or printing a preview of an HTML document. At the moment, I do not want to avoid breaks, and I do not want to determine exactly where to put the break. I know the page-break- * elements as defined in CSS 2.1 and CSS 3.0. I really want to find out the last element on the current page and the first element on the next page and associate them with the actual HTML code.

As far as I know, there are no events or signals for which I could register. The next thing I was thinking about is patch webkit or gecko and add a custom signal / event. But this is only possible if the page break code is not scattered too many files and members.

I do not ask for a complete solution, but rather any thoughts or hints on how this can be achieved at all.

Thanks in advance for any suggestions or ideas :)

UPDATE: I need to find out that the position of the page is broken programmatically, since I want to change and process the original HTML file depending on the result.

+4
source share
1 answer

What exactly are you trying to achieve? You can create pages according to page breaks and whether to print the page using only CSS with multimedia requests .

If the CSS for your use case is not enough and the rendering fix is ​​the right solution: on Gecko you can grep nsCSSFrameConstructor.cpp to call AddPageBreakItem and then find out where it inserts the breaks. Paginated nsPresContext is a frame for printing or previewing. Look for calls in nsPresContext :: IsPaginated and nsPresContext :: IsRootPaginatedDocument.

0
source

Source: https://habr.com/ru/post/1445545/


All Articles