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.
Error is
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(); } }
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
Comment