10

Has anyone found a good class, or other file that will convert a .doc file into html or something that I can read and turn into html?

I have been looking around for a couple hours now and have only found ones that require msword on the server in order to convert the file. I am pretty sure that is not an option but I have not actually talked to my hosting provider about it.

The goal is for a user to be able to upload the file to my server and the server handle the conversion and then display it as html, much like googles view as html feature.

corymathews
  • 12,289
  • 14
  • 57
  • 77

5 Answers5

6

intall and use abiword, like this:

AbiWord --to=html archivo.doc

you can call this command from php.

CronosNull
  • 1,353
  • 15
  • 24
3

A project called phpLiveDocx does what you want. It is a SOAP based service, but can be used free of charge. For a basic introduction, please see: http://www.phplivedocx.org/articles/brief-introduction-to-phplivedocx/

0

This PHP uploads your *.DOC file to a upload folder and opens it up in HTML.

<?php
function content($file){
$data_array = explode(chr(0x0D),fread(fopen($file, "r"), filesize($file)));
$data_text = "";
foreach($data_array as $data_line){
if (strpos($data_line, chr(0x00) !== false)||(strlen($data_line)==0))
{} else {if(chr(0)) {$data_text .= "<br>";
                      $data_text .= preg_replace("/[^a-zA-Z0-9\s\,\.\-\n\r\t@\/\_\(\)]/","",$data_line); 
       } 
   }        
}
return $data_text;}
$destination = str_replace('index.php', '', $_SERVER['SCRIPT_FILENAME']);
$destination.= "upload/";
$maxsize = 5120000;
if (isset($_GET['upload'])) {
      if($_FILES['userfile']['name'] && $_FILES['userfile']['size'] < $maxsize) {
      if(move_uploaded_file($_FILES['userfile']['tmp_name'], "$destination/".$_FILES['userfile']['name'])){
      $file = $destination."/".$_FILES['userfile']['name'];
      $data = content($file);
      echo $data;
        }   
         }
}else{
      echo "<form  enctype='multipart/form-data' method='post' action='index.php?upload'>
            <input name='userfile' type='file'>
            <input value='Upload' name='submit' type='submit'>
            </form>";
      }
?>
andrewsi
  • 10,807
  • 132
  • 35
  • 51
forever99
  • 9
  • 2
0

Install open office on your system and run this on the command line:

/usr/bin/soffice -headless "macro:///Standard.Convert.SaveAsHtml(test.doc)"

  • thanks Anthony, but i could not find any documentation about that. could you provide a reference? – Alexar Dec 13 '10 at 14:16
0

You can do it through openoffice with unoconv http://dag.wieers.com/home-made/unoconv/ Really great tool.

mvod
  • 135
  • 2
  • 9