Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rendering page breaks in word with html

I am generating documents with php in word and pdf format

I am using headers to generate a document in word

header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=example.doc");
echo "<html>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">";
echo "<body>"; etc etc

The wysiwyg is creating the following code to render pagebreaks

<div style="page-break-after: always;"><span style="display: none;">&nbsp;</span></div>

This html/css is working fine for the pdf output but not the word.

Can someone recommend an alternative method to create page breaks that may work in word.

like image 464
user1019144 Avatar asked Nov 21 '11 20:11

user1019144


3 Answers

The question was asked a while ago but I'm adding this for reference:

I had the same issue and was able to make a page-break with this code

<br style="page-break-before: always">

The only way I could get it to work was with the "br" element and style it inline.

like image 127
MichaelSmith Avatar answered Oct 17 '22 17:10

MichaelSmith


Inserting either of the following (where you want a page break) will work with MS Word 2000-2007 (and possibly with later versions):

1) <br clear=all style='page-break-before:always'>

2) &#12; /* Ctrl-L = FF */

like image 4
cdgoldin Avatar answered Oct 17 '22 16:10

cdgoldin


You will be scratching your head to figure out how Microsoft plays with the standards to force their own standards.

Try making a Word document with a page break - i.e. two pages. Save it as HTML and check the generated code for what style + tag combination is working for them.

Be aware that Word 2000 styling might be different from Word 2003 - which might be different from Word 2007 again - which might be different from Word 2010 again.

So adjust the solution based on which version of Word you are using because such differences are always there in Microsoft products. One similar issue is: Outlook 2003 uses the Internet Explorer engine to render HTML emails, while Outlook 2007 uses the Word rendering engine. HTML email showing with correct styles and fonts in Outlook 2003 will not show properly in Outlook 2007.

like image 2
user769889 Avatar answered Oct 17 '22 16:10

user769889