2

i need to create a .doc file that has more than one page. I want to create the doc file from html (setting the headers so that it is interpreted as a doc file) but i don't know how to add a page break in html that is correctly recognized from word.

Thanx in advance

Nicola Peluchetti
  • 76,206
  • 31
  • 145
  • 192

1 Answers1

5

You may find PHPWord to be useful.

PHPWord is a library written in PHP that create word documents.

Update:

Method One:

Here is a method using COM (requires Word to be installed)

Method Two:

Use appropriate headers, here is an example:

header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=document_name.doc");

echo "<html>";
echo "<body>";
echo "<b>My first document</b>";
echo "</body>";
echo "</html>";
Sarfraz
  • 377,238
  • 77
  • 533
  • 578
  • Cool. But it creates .docx files, not .doc. I was looking forward to seeing PHP code that generates a .doc file. Still, nice to know PHPWord is there. – eje211 Jul 27 '10 at 10:23
  • @alcuadrado: You are right but now i have updated my answer :) – Sarfraz Jul 27 '10 at 10:33
  • @sAc, method two is what i meant. I was just wondering if there was an html tag that would interpreted by MsWord as a page break! – Nicola Peluchetti Jul 27 '10 at 12:08
  • Actually the best way to do what i wanted to do is to create an html file on the server, pass it to the open-office converter to create a .doc file and then send it back to the client! Thx for your posts! – Nicola Peluchetti Jul 29 '10 at 10:32
  • @Nicola Peluchetti: Page break works with `
    `
    – binarious Sep 05 '11 at 10:55