import java.io.IOException;
public class PdfReader {
public static final String FILEPATH = "d:\\xpdf\\pdftotext.exe";
public static void convertToTxt(String filePath , String txtFile) {
//保留文件原始布局
String layout = "-layout";
// 设置编码方式
String encoding = "-enc";
String character = "GBK";
// 设置不打印任何消息和错误
String mistake = "-q";
// 页面之间不加入分页
String nopagebrk = "-nopgbrk";
String[] cmd = new String[]{FILEPATH , layout , encoding , character , mistake , nopagebrk , filePath , txtFile};
try {
Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
convertToTxt("c:\\1.pdf" , "c:\\a.txt");
}
}
还有一个pdftohtml.exe 在附件中 , 放在xpdf文件夹下面 。 可以使用pdftohtml.exe -enc GBK #FROM# #TO#的形式解决 , 可以把pdf转换成pdf文档。