Ask HN: How does Google Docs do print layouts?

1 points by partisan ↗ HN
I am trying to figure out if there is an HTML WYSIWYG editor available that displays documents in a print view mode the way Google Docs. If not, how does Google accomplish it?

1 comment

[ 3.0 ms ] story [ 8.0 ms ] thread
Not that I'm aware of. Most wysiwyg editor libraries rely on contenteditable and they all (?) use the browser's layout engine, which doesn't give you access to pagination.

Google just wrote their own layout engine. Open your browser's dev tools and watch what it's doing to the DOM as you edit text- it essentially positions each glyph as it sees fit.

I'm not aware of any easily available package that can do the same. I wish there was, I've actually started to write something but quickly got intimidated at the enormity of the task.

Even draftjs or quill which have a very cool input/editing story still use the browser's layout engine to render the text so you'll never have the level of control gdocs does.