Convert Msdoc file to text on linux

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • udaypawar
    New Member
    • Feb 2007
    • 29

    #1

    Convert Msdoc file to text on linux

    Hi all,

    I am here back with some doubt.

    Can I convert Msdoc file to text file on Linux environment without using any third party software.

    I want it either by Java class or PHP. As its shared environment its not possible to install any software over there. It already has PHP and Java installed.

    Can any one help me with that.
  • udaypawar
    New Member
    • Feb 2007
    • 29

    #2
    Originally posted by udaypawar
    Hi all,

    I am here back with some doubt.

    Can I convert Msdoc file to text file on Linux environment without using any third party software.

    I want it either by Java class or PHP. As its shared environment its not possible to install any software over there. It already has PHP and Java installed.

    Can any one help me with that.
    I have tried to read the document with fread and fopen and it can give me text but it contains all the other Junk characters.

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hi.

      I've seen a couple of PHP classes that do this but they will only work on Windows and need MS Word to be installed.

      You will probably need to write a parser to convert the Doc formatted text into plain text.

      Comment

      • udaypawar
        New Member
        • Feb 2007
        • 29

        #4
        Thanks for reply..

        Now i am planning to use below given java class in my PHP application. I got this code while searching on google and i tried to compile it, it is giving me an error for class HWPFDocument.

        I have import all the other classes libraries. But on google it is showing me that this class is from org.apache.poi. hwpf.HWPFDocume nt and my code is giving me compile time error.

        If i could resolve this problem then will use this java class in my application. Any help is appreciated.
        [code=java]
        import java.io.*;
        import java.io.FileInp utStream;
        import java.io.InputSt ream;
        import java.io.FileWri ter;

        public class MsDoc {
        public static void main(String args[]) {
        try
        {
        //args[0] Microsoft document
        //args[1] Destination
        FileInputStream fis = new FileInputStream (args[0]);
        HWPFDocument doc=new HWPFDocument(fi s);
        String str="";
        Object[] textStack=doc.g etTextTable().g etTextPieces(). toArray();
        for (int i=0; i<textStack.len gth; i++) {
        if(str=="")
        str=((TextPiece )textStack[i]).getStringBuff er().toString() ;
        else
        str=str+" "+((TextPiece)t extStack[i]).getStringBuff er().toString() ;
        }
        FileWriter fw=new FileWriter("D:\ \newdoc.txt");
        fw.write(str);
        fw.close();
        System.out.prin tln(args[0]);
        }
        catch (Exception e) {
        System.out.prin tln("Error while reading file");
        }
        }
        }[/code]
        Last edited by pbmods; Sep 10 '07, 12:35 PM. Reason: Added CODE tags.

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Heya, Udaypawar.

          Please use CODE tags when posting source code:

          &#91;CODE=ja va]
          Java code goes here.
          &#91;/CODE]

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            I found this link at the apache site.
            You probably need to download the jar packages from there and unzip them into your project.

            I'm no good with Java so I'm afraid I not much help with this.
            You may want to ask about this in the Java forums.

            Comment

            • udaypawar
              New Member
              • Feb 2007
              • 29

              #7
              I got some idea about it. Its very simple we just needs to read content from msword file as we do normally. Word appends some trailing and leading binary characters to the text content. We have to calculate and remove it. Then we have to remove some ASCII characters from the code which are introduced by Msword.

              I have written some code but yet its not much clean. Also have to test it on Linux environment as currently I am doing it on windows server.

              Comment

              • udaypawar
                New Member
                • Feb 2007
                • 29

                #8
                I have tried using fread but no success so again switched to antiword. Using shellexec function of php i am invoking antiword also passing required parameters. Then it will created a text file on specified location which i am reading for extracting text. No other solution is found yet...

                Comment

                • Motoma
                  Recognized Expert Specialist
                  • Jan 2007
                  • 3236

                  #9
                  You might want to take a look at Apache POI.

                  Comment

                  Working...