I am currently working with this great tool Jacob, but I get something very strange. Reading a MS Word file, I tokenize the document and, for each token I get, I would like to have also the page and line number. THE strange thing is that it works only if I start MSWord myself and get the instance from Jacob. If Java starts a new instance, I cannot get these information. The other point is that I get many information from the file, that work great, so it seems as if the only trouble is dealing with the Information property.
Parts of my code are :
ActiveXComponent myApplication = ActiveXComponent.connectToActiveInstance("Word.Application");
if (myApplication == null) {
myApplication = new ActiveXComponent("Word.Application");
}
Dispatch myDocuments = myApplication.getProperty("Documents").toDispatch();
Dispatch myDocument = getOpenedDocument(myDocuments, pFilePath);
....
Dispatch myParagraphs = Dispatch.call(myDocument, "Paragraphs");
Dispatch myParagraph = Dispatch.call(myParagraphs, "Item", new Variant(1)).toDispatch();
Dispatch myParagraphRange = Dispatch.get(myParagraph, "Range").toDispatch();
Then for exemple when I try :
myText = Dispatch.get(myParagraphRange, "Text").toString();
I get the paragraph content. But with :
int myPageNumber = Dispatch.call(myParagraphRange, "Information", 3).getInt();
IF and ONLY if MSWord isn't started by myself, I get :
com.jacob.com.ComFailException: A COM exception has been encountered:
At Invoke of: Information
Description: Le serveur a généré une exception.
It seems that the "Information" property is having problems with Word ???