Dynamically Insert Pagebreak

amexn picture amexn · Dec 6, 2011 · Viewed 7.9k times · Source

My team working in a project using asp.net mvc3(c#). Based on the project requirement,we need to implement page break like Microsoft Word. I need to save the pagebreak and the page size may be a4, letter, legal, etc.

Is it possible to control the page size of the content in the ckeditor and insert page breaks shown inside the editor when it crosses a certain height or size, the same way it works in MS Word>

Is there is any alternative solution?

Answer

Anders Tornblad picture Anders Tornblad · Dec 6, 2011

Like graphicdivine says, use print CSS to accomplish what you need to do. Create a css class that has a page-break-before definition, and dynamically add that class to the first element of the page after the break.

You could also do something like this:

br.pageBreak {
    page-break-after: always;
}

and then insert a <br class="pageBreak" /> at the point where you need a page break.

More info:

Page-breaks: http://www.w3.org/TR/css-print/#s.8.2

Page size: http://www.w3.org/TR/css-print/#s.8.3

An old A List Apart article: http://www.alistapart.com/articles/goingtoprint/

Unfortunately, I do not know if it is possible to alter CKEditor in this way without hassle.