Basically, you need two divs, for example
<div id='pageWrapper'> <div id='page' style='max-height: 600px; overflow: hidden;'> </div> </div>
All #pageWrapper really sits there and looks like a page, all the content that someone adds is added to the # page. Every time someone adds content, whether by pasting or typing #page scrollHeight and offsetHeight. If scrollHeight is larger, you have overflowed the page, and you can start moving content (word by word or element by element) to the next page until scrollHeight equals offsetHeight.
If the user inserts a page break, just set the page height, wherever the page break is, so everything that comes after that will fill the page. It will be difficult with large documents, because if someone overflows page 1, the content will need to be adjusted until the page is empty, but I think that Google Docs has no pages.
source share