Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert a page break in a generated HTML .doc

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();
like image 203
baked Avatar asked Feb 04 '11 10:02

baked


1 Answers

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).

like image 189
CodePB Avatar answered Sep 28 '22 16:09

CodePB