Word to Text

Posted on 2004-04-02
Last Modified: 2008-02-01
Hi All

How can I get the text from Word Document

Question by:lakkiprasanna
  • 4
  • 2
LVL 14

Expert Comment

ID: 10740144
You can use textmining api for this
LVL 14

Expert Comment

ID: 10740150
Download api from

LVL 14

Expert Comment

ID: 10740210
A sample example

//package org.prithvi.test;


 * <p>Title: Parsers</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0

public class Word2Text {

  public static void main(String[] args) throws Exception{
     java.util.Date start=new java.util.Date();
       java.util.Date end=new java.util.Date();

       successLog.append("\n\nTotal No of Successfull parsed files: "+success);
        successLog.append("\n\nTotal No of  files: "+(success+error));
         successLog.append("\n\nTotal Execution Time(in milli seconds): "+(end.getTime()-start.getTime()));

      errorLog.append("\n\nTotal No of bad files : "+error);
  errorLog.append("\n\nTotal No of  files: "+(success+error));
   errorLog.append("\n\nTotal Execution Time(in milli seconds): "+(end.getTime()-start.getTime()));

   FileOutputStream fout=new FileOutputStream("success.textmining.log");
   fout=new FileOutputStream("error.textmining.log");


  static int success=0;
  static int error=0;

  public static void SearchFile(String strFile)
      java.util.Date start = new java.util.Date();

      File f=new File(strFile);
      long size=f.length() ;

            FileInputStream fin=new FileInputStream(strFile);
            org.textmining.text.extraction.WordExtractor extractor=new org.textmining.text.extraction.WordExtractor();
            String str=extractor.extractText(fin);            
            java.util.Date end=new java.util.Date();
            String str2="\nParsed Time(in milli seconds) :"+(end.getTime()-start.getTime());
            start=new java.util.Date();
            FileOutputStream fout=new FileOutputStream(strFile+".textmining.txt");
            end=new java.util.Date();
            String str1="\nWriting Time(in milli seconds) :"+(end.getTime()-start.getTime());
//             java.util.Date end = new java.util.Date();
              successLog.append("\n\nFile :"+strFile) ;
              successLog.append("\nFile Size (in bytes):"+size) ;
              successLog.append("\nOutput File :"+strFile+".textmining.txt") ;
              successLog.append("\nStart Time:"+start) ;
              successLog.append("\nEnd Time :"+end) ;

    catch(Exception Exe)
      java.util.Date end = new java.util.Date();
      errorLog.append("\n\nFile :"+strFile) ;
      errorLog.append("\nFile Size:"+size) ;
      errorLog.append("\nStart Time:"+start) ;
      errorLog.append("\nEnd Time :"+end) ;
      errorLog.append("\nTime in Milli Seconds :"+(end.getTime()-start.getTime() )) ;
      errorLog.append("\nException :"+Exe) ;


  public static void SearchFolder(String strFile) throws Exception
    File file=new File(strFile);
    if(file.isDirectory()==false )
      errorLog.append("\n\n"+strFile+" is not directory") ;
    String files[]= file.list() ;
    for(int i=0;i<files.length ;i++)
     String docFile=files[i];
     docFile.toLowerCase() ;
      if(docFile.endsWith(".doc") )



  static StringBuffer errorLog=new StringBuffer("");
  static StringBuffer successLog=new StringBuffer("");
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

LVL 13

Expert Comment

ID: 10740216
Hi  lakkiprasanna,

See also
LVL 30

Expert Comment

by:Mayank S
ID: 10740415
You also have:
LVL 30

Expert Comment

by:Mayank S
ID: 10740424
By the way, why does this question have 495 points ;-) ? 500 is unlucky? :-)
LVL 14

Accepted Solution

sudhakar_koundinya earned 495 total points
ID: 10746354


Text Mining is basically developed using POI API only.

It concentrates on MS office Document formats for both reading and writing

Text Mining

It is concentrating on different document formats for getting only text (i.e. reading only). Developer of text mining API is also developer of POI API. you can check different apis from single api in near future at thi site (just for text extraction only)

Some of problems that are raising in POI API are  fixed in textmining. Jakarta didn't released fully functional POI (still working on HWPF formats - I mean Word Document Formats)

Currently POI is supporting word97 to word 2003 formats. Whereas Textmining is giving support for Word 6.0 Formats also. I have communicated to developer of POI API for word2.x version. And I have contributed my self  with sample code for word 2.x formats.
The code for word2.x is listed at
So we may see the word2.x support in near future (a positve hope :-))

BOTH textmining and poi api does not have support for fast saved (complex) documents.


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
runtime exception 2 41
difference between sorce folder and folder in eclipise 3 28
jboss 7.1 start up error 1 30
ejb entity bean example 2 8
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question