I am currently generating a .doc file as html using asp.NET.
I wish to insert a page break to the page but don't know how.
I've tried using the css style='page-break-before:always' but it does nothing.
This is the code assigned to a button click event:
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset ="";
HttpContext.Current.Response.ContentType ="application/msword";
string strFileName = "GenerateDocument"+ ".doc";
HttpContext.Current.Response.AddHeader("Content-Disposition","inline;filename=" + strFileName);
StringBuilder strHTMLContent = new StringBuilder();
strHTMLContent.Append("<p align='Center'>Content Before Page Break</p>".ToString());
strHTMLContent.Append("<br><br>".ToString());
strHTMLContent.Append("<p class='pageBreak' style='mso-special-character:line-break;'>meh</p>".ToString());
strHTMLContent.Append("<br><br>".ToString());
strHTMLContent.Append("<p align='Center'>Content After Page Break</p>".ToString());
HttpContext.Current.Response.Write(strHTMLContent);
HttpContext.Current.Response.End();
HttpContext.Current.Response.Flush();
Word has its own special classes. mso-special-character:page-break; does work in this situation, as mentioned by Pekka, however what is missing is this should be on a <br> tag. So the following code will work:
<br clear=all style='mso-special-character:line-break;page-break-before:always'>
It's not particularly nice solution, but in my case I had no choice (I didn't write the original code, and it was a much bigger job to change it).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With