情参考:http://www-900.ibm.com/developerWorks/cn/java/l-java-tips/index.shtml抽取支持中文的pdf文件-xpdfimport java.io.*;
/**
 * <p>Title: pdf extraction</p>
 * <p>Description: email:[email protected]</p>
 * <p>Copyright: Matrix Copyright (c) 2003</p>
 * <p>Company: Matrix.org.cn</p>
 * @author chris
 * @version 1.0,who use this example pls remain the declare
 */
public class PdfWin {
  public PdfWin() {
  }
  public static void main(String args[]) throws Exception
  {
    String PATH_TO_XPDF="C:\\Program Files\\xpdf\\pdftotext.exe";
    String filename="c:\\a.pdf";
    String[] cmd = new String[] { PATH_TO_XPDF, "-enc", "UTF-8", "-q", filename, "-"};
    Process p = Runtime.getRuntime().exec(cmd);
    BufferedInputStream bis = new BufferedInputStream(p.getInputStream());
    InputStreamReader reader = new InputStreamReader(bis, "UTF-8");
    StringWriter out = new StringWriter();
    char [] buf = new char[10000];
    int len;
    while((len = reader.read(buf))>= 0) {
    //out.write(buf, 0, len);
    System.out.println("the length is"+len);
    }
    reader.close();
    String ts=new String(buf);
    System.out.println("the str is"+ts);
  }
}

解决方案 »

  1.   

    拷贝一下doc
     Process exec(String command) 
              Executes the specified string command in a separate process. 
     Process exec(String[] cmdarray) 
              Executes the specified command and arguments in a separate process. 
     Process exec(String[] cmdarray, String[] envp) 
              Executes the specified command and arguments in a separate process with the specified environment. 
     Process exec(String[] cmdarray, String[] envp, File dir) 
              Executes the specified command and arguments in a separate process with the specified environment and working directory. 
     Process exec(String cmd, String[] envp) 
              Executes the specified string command in a separate process with the specified environment. 
     Process exec(String command, String[] envp, File dir) 
              Executes the specified string command in a separate process with the specified environment and working directory.