Java from Word and PDF files of the four arms (1)
Many people used to document java operation often encountered a problem is how to get word, excel, such as pdf documents? I studied, in the summing up from word here, pdf Methods.
1. Use jacob
In fact, jacob is a bridage connecting com or win32 java and function of a middleware, and not directly from jacob word, excel, and other documents, the need to write their own dll Oh, but has been written for you, is the author of a jacob and provided.
Jacob jar and dll file downloads: http://danadler.com/jacob/
Jacob downloaded into the designated path and after (dll into path, jar files on classpath), we can write your own extraction procedure, the following is a simple example:
Import java.io.File;
Import com.jacob.com .*;
Import com.jacob.activeX .*;
/ **
* Title: pdf extraction
* Description: email: chris@matrix.org.cn
* Copyright: Matrix Copyright (c) 2003
* Company: Matrix.org.cn
* @ Author chris
* @ Version 1.0, who use this example pls remain the declare
* /
(Public class FileExtracter
Public static void main (String [] args) (
ActiveXComponent component = new ActiveXComponent ( "Word.Application");
String inFile = "c: test.doc";
String tpFile = "c: temp.htm";
String otFile = "c: temp.XML";
Boolean flag = false;
Try (
Component.setProperty ( "Visible", the new Variant (false));
Object wordacc = component.getProperty ( "document."). ToDispatch ();
Object wordfile = Dispatch.invoke (wordacc, "Open", Dispatch.Method,
New Object [] (inFile, new Variant (false), the new Variant (true)),
New int [1]). ToDispatch ();
Dispatch.invoke (wordfile, "SaveAs" Dispatch.Method, new Object [] (
TpFile, new Variant (8)), new int [1]);
Variant f = new Variant (false);
Dispatch.call (wordfile, "Close", f);
Flag = true;
) Catch (Exception e) (
E.printStackTrace ();
Finally ()
Component.invoke ( "Quit" new Variant [] ());
)
)
)






