Convert document file into rtf file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nanaveraa
    New Member
    • May 2008
    • 9

    Convert document file into rtf file

    Hai,
    i am tried to convert a .doc file into .rtf format file using jacob jar.i am written a code but its gives some error. In below i given that programs and error.please give me the solution to solve the problem.
    Code:
    import java.io.*;
      import java.io.File;  
    import com.jacob.com.*;
      import com.jacob.activeX.*;   
      public class convertDoc2Rtf {       
      private final static String DOC_FORMAT = ".doc";  
        private final static String RTF_FORMAT = ".rtf";     
           public convertDoc2Rtf(){} 
            public static void main(String[] args)throws IOException {           try{            
      String fileName = "D:/test.doc";              if(fileName.lastIndexOf(DOC_FORMAT) == fileName.length() - DOC_FORMAT.length())
     {              
    String strDoc = new File(fileName).getAbsolutePath();  String strRtf = new String(strDoc.substring(0, strDoc.lastIndexOf(DOC_FORMAT)) + RTF_FORMAT);      
                    ActiveXComponent oWord = new ActiveXComponent("Word.Application");                      oWord.setProperty("Visible", new Variant(false));                                    Dispatch oDocuments = oWord.getProperty("Documents").toDispatch();          Dispatch oDocument = Dispatch.call(oDocuments, "Open", strDoc).toDispatch();        
      Dispatch oWordBasic = (Dispatch) Dispatch.call(oWord, "WordBasic").getDispatch();          
    Dispatch.call(oWordBasic, "FileSaveAs", strRtf);          Dispatch.call(oDocument, "Close", new Variant(false));                            oWord.invoke("Quit", new Variant[0]);                  System.out.println(strRtf);              }         
     }catch(Exception e)
    {System.out.println("Exception "+e);}         // convertDoc2Rtf converter = new convertDoc2Rtf();         }    
     }
    Error is
    Code:
    Exception in thread "main" java.lang.UnsatisfiedLinkError: createInstanceNative          at com.jacob.com.Dispatch.createInstanceNative(Native Method)          at com.jacob.com.Dispatch.<init>(Dispatch.java:161)          at com.jacob.activeX.ActiveXComponent.<init>(ActiveXComponent.java:54)          at projectbytes.convertDoc2Rtf.main(convertDoc2Rtf.java:24)
    Java Result: 1
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Why are you using jacob.jar for that? Use Apache's poi.

    Comment

    • nanaveraa
      New Member
      • May 2008
      • 9

      #3
      Originally posted by r035198x
      Why are you using jacob.jar for that? Use Apache's poi.
      Thankyou for your reply

      In poi we are only read the file and i don't know how to convert the file.so pls give me the idea to do this.

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Who or what formatted your soure code? A firecracker? It is completely unreadable.

        kind regards,

        Jos

        Comment

        • nanaveraa
          New Member
          • May 2008
          • 9

          #5
          Originally posted by JosAH
          Who or what formatted your soure code? A firecracker? It is completely unreadable.

          kind regards,

          Jos

          It is java code using jocob jar. It downloaded on site.

          Thank U 4 your response,
          Nan Averaa

          Comment

          • manishvrm
            New Member
            • Oct 2008
            • 1

            #6
            hi sir....


            i need to convert .doc file to .html file in java..plz help sir..

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by manishvrm
              hi sir....


              i need to convert .doc file to .html file in java..plz help sir..
              What have you done about it so far?

              Comment

              Working...