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.