How can I convert a Microsoft Word document to html in php? I am using windows, and heard that the COM package does it.
Asked
Active
Viewed 1.6k times
2 Answers
4
See the COM extension of PHP.
Example of the usage by the PHP site:
<?php
// starting word
$word = new COM("word.application") or die("Unable to instantiate Word");
echo "Loaded Word, version {$word->Version}\n";
//bring it to front
$word->Visible = 1;
//open an empty document
$word->Documents->Add();
//do some weird stuff
$word->Selection->TypeText("This is a test...");
$word->Documents[1]->SaveAs("Useless test.doc");
//closing word
$word->Quit();
//free the object
$word = null;
?>
-
1Just be aware that using word unattended on any kind of server opens up a great big can of worms, as it's not really designed for that. People have done it though. – DarinH Jan 13 '11 at 22:38
0
Try to use Print2Flash for obtaining a working HTML page that displays the original Word document. Formatting, fonts and images are not lost and preserved with this solution. One may get a working PHP sample demonstrating how it can be done from p2f SDK available for download here: http://print2flash.com/download.php Besides SDK it is needed to download and install Print2Flash itself form the same page. the PHP code is quite simple and the minimum code seems to be like this:
$p2f = new COM("Print2Flash4.Server2")
$p2f->ConvertFile($sourcefile,$fsname);
There are also a lot of additional options you may set here. Please see the full sample code from the sdk to learn about these options.

Sindbad
- 1