7

I'm trying to figure out where a browser, specifically firefox or chrome, would insert page breaks when printing or print previewing an HTML document. For now I do not want to avoid the breaks, nor do I want to define where exactly to put a break. I'm aware of the page-break-* elements as defined in CSS 2.1 and CSS 3.0. I really want to figure out the last element on the current page and the first element on the next page and relate them to the actual HTML code.

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

I'm not asking for a complete solution, rather any thoughts or hints how this could be accomplished at all.

Thanks in advance for any suggestions and ideas :)

UPDATE: I need to figure out the position of the page breaks programmatically as I want to modify and manipulate the original HTML file depending on the result.

curiosity
  • 388
  • 1
  • 13
  • 1
    If you just try to print the webpage you will get an idea of where the cut off will be, isn't that enough? – Andy Nov 12 '12 at 15:14
  • 1
    No, I need to figure out the position of the page breaks programmatically. – curiosity Nov 12 '12 at 15:15
  • This is tricky. But if the page size was determined, you may warp everything up in a wrapper div, and set the size to the page size. Now just find out which element is out of the box. – xiaoyi Nov 12 '12 at 16:39

1 Answers1

0

What exactly are you trying to achieve? You can style pages according to page breaks and whether the page is being printed using only CSS with media queries.

If CSS is not enough for your use case and patching the renderer is a suitable solution: on Gecko, you can grep nsCSSFrameConstructor.cpp for calls to AddPageBreakItem, and then figure out where it's inserting the breaks. A paginated nsPresContext means this is a frame for printing or print-preview. Look for calls to nsPresContext::IsPaginated and nsPresContext::IsRootPaginatedDocument.

Reuben Morais
  • 1,013
  • 1
  • 8
  • 20
  • Well, thanks for the heads up. I will have a look! What I want to do is indicate in the HTML source code displayed in the editor, where a page break will occur. I'm aware of the page-break-* elements, as well as the fact, that web pages are rendered differently by different browsers. – curiosity Nov 13 '12 at 09:06