views:

548

answers:

1

Hi, Is it possible to implement paging similar to MS Word in a rich text editor using JavaScript.

I need to implement an editor using JavaScript that contains text in pages. If i type text that exceeds the ficed limit of a page then automatically a new page is created and text overflows to the new page with formatting intact. Also if I copy large text from another source then it should calculate the number of pages depending on the text length and divide it into pages with all the formatting of the original text.

I need to break the text into lines based on pixel size using only JavaScript, HTML and CSS.

If i delete contents from inside a page then contents from the next page should be populated in the current page and if all the contents from a page is deleted then the page should be deleted. Almost every paging feature in MS word should be implemented in this one.

+1  A: 

Sure it's possible. One implementation might be to count lines of text while considering line-height/font-size.

apphacker
but i need to implement it based on pixel size and not on font size.
rahul
and also i need to implement it using javascript, HTML and CSS
rahul
you can get the pixel size on fonts using JS
alex
but what if the font size is in percentage or em or any other unit
rahul
Yeah, I've had font sizes in ems and have had JS get the height. You'll need to also work out paddings/margins/line height etc. This will be complicated.
alex
Ya you are right. Also the major problem occurs when there's no specified font size and it derives from the parent tag.
rahul