hi
please do tell me how to convert a microsoft word to html document.
In my appln the user will browse the microsoft word document,when a registered user tries to view the application loaded by the users of the website...it should display in html format....

Recommended Answers

All 14 Replies

In word do:
File -> Save as.. -> Type name and select webpage (*.htm,*.html) in the extension menu.

This is the only way to convert .doc to .html. Microsoft is very protective about there fileformats.
(well you could get a morgage and buy the microsoft SDK..)

I strongly advise you to NOT use Word as a tool to create web pages. The Microsoft HTML conversion utility generates horrible code.

Member Avatar for fatihpiristine

I strongly advise you to NOT use Word as a tool to create web pages. The Microsoft HTML conversion utility generates horrible code.

yea!

hi,
in my application the user will upload a word document...but when the admin open the page it should get displayed in html format.i want the conversion to automatic....................

Kings,

I asked a similar question in this forum before I saw your post. I've been doing some additional research since I posted and found a PHP script that is suppose to convert word docs to HTML automatically with the help of free program called "wvWare".

The script is located here: http://instruform.com/wordconv.phps

wvWare is located here: http://wvware.sourceforge.net/

Now I don't have any idea if these will work, but will be looking into them further for my own purposes. I hope this helps.

Good luck!

Yproc

Me too facing the same problem if any one finds solution then let me inform.The problem is about writing whole php code to convert a MS Word document to HTML format which i am using to upload resume.

I've tried to use ConvertDoc to convert word and pdf resumes to html code. Unfortunately, it doesn't get invoked from PHP. The shell takes the command fine, my php safe mode is off, and I have all permission to the System user on the executable. My code is below; I don't see any problem with it.

<?php
      $command='convertdoc /S resume_sd.doc /T resume_new.html /M2 /C2 /F9';
      echo $command;
      echo exec($command);
?>

Is there a remedy for this?

Member Avatar for diafol

This sounds like a particularly horrible thing to try and achieve. You probably need to use COM. I bet the various versions of Word will also throw a spanner in the works. If such a script exists, I reckon it'll be a commercial thing.

As for the wvware - it's C++ I think.

Thanks, Chris, but I wanted to store HTML code in a database

<?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;}
$file = "/home/user/file.doc";
$data = content($file);
echo $data;
?>

This PHP Code Converts the $file supplied into HTML and Display's it on a webpage.

// This is an improvement on the the last post adding uploading your Doc file to be Displayed

<?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>";
      }
?>

Hi All,

Below code for .doc, doesn't covert header-footer part into TEXT:-

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;}
$html = content($userDoc);

:: My requirement is to convert .doc/.docx/.rtf file into HTML. Can anybody help to read header-footer part as well into text.

Thanks in advance
Nitin

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.