user1019144
user1019144

Reputation: 1253

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.

Upvotes: 13

Views: 22586

Answers (5)

Wooderson
Wooderson

Reputation: 23

Adding another answer in case it's any use. None of the above worked for me in Word 365, but the following did:

<p style="page-break-after: always;">&nbsp;</p>

Upvotes: 1

adesh sachan
adesh sachan

Reputation: 89

<pre><br clear=all style='mso-special-character:line-break;page-break-before:always'></pre>

This is working for me to break content into next page.

Upvotes: 3

cdgoldin
cdgoldin

Reputation: 41

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 */

Upvotes: 4

user769889
user769889

Reputation: 376

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.

Upvotes: 2

MichaelSmith
MichaelSmith

Reputation: 719

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.

Upvotes: 33

Related Questions