
.doc to html converter in java

it's urgent buddies

Hi Friend,
Try the following code:
import java.io.*;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;
public class ConvertDocToHTML {
public static void main(String[] args) {
File file = null;
WordExtractor extractor = null ;
try {
file = new File("c:\\Hello.doc");
FileInputStream fis=new FileInputStream(file.getAbsolutePath());
HWPFDocument document=new HWPFDocument(fis);
extractor = new WordExtractor(document);
String data="";
String [] fileData = extractor.getParagraphText();
for(int i=0;i<fileData.length;i++){
if(fileData[i] != null)
data+=fileData[i]+" ";
}
BufferedWriter out=new BufferedWriter(new FileWriter("C:/Hello.html"));
out.write("<html>");
out.newLine();
out.write("<body>");
out.newLine();
out.write("<p>"+data+"</p>");
out.newLine();
out.write("</body>");
out.newLine();
out.write("</html>");
out.close();
}
catch(Exception ex){}
}
}
For the above code, you need the following jar files:
poi-scratchpad-3.7-20101029.jar
poi-3.7-20101029.jar
Hope that the above code will be helpful for you.
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.