如何使用xpdf把本地磁盘上的pdf转化为txt
来源:互联网 发布:在韩国能用淘宝吗 编辑:程序博客网 时间:2024/05/18 02:21
一:下载工具包:
可到该账户下下载
二:工作路径设置:
三:文件配置:
1:修改1:
cidToUnicode Adobe-GB1 C:/xpdftest/xpdf/xpdf-chinese-simplified/Adobe-GB1.cidToUnicode
unicodeMap ISO-2022-CN C:/xpdftest/xpdf/xpdf-chinese-simplified/ISO-2022-CN.unicodeMap
unicodeMap EUC-CN C:/xpdftest/xpdf/xpdf-chinese-simplified/EUC-CN.unicodeMap
unicodeMap GBK C:/xpdftest/xpdf/xpdf-chinese-simplified/GBK.unicodeMap
cMapDir Adobe-GB1 C:/xpdftest/xpdf/xpdf-chinese-simplified/CMap
toUnicodeDir C:/xpdf/chinese-simplified/CMap
#displayCIDFontTT Adobe-GB1 /usr/..../gkai00mp.ttf
#----- end Chinese Simplified support package
2:修改2:
# If set to "yes", text extraction will insert page
# breaks (form feed characters) between pages. This
# defaults to "yes".
textPageBreaks no
3:修改3:
四:在Myeclipse中启动工程
import java.io.File;
import java.io.IOException;
public class XpdfToText {
// PDF文件名
private File pdffile;
// 转换器的存放位置,默认在c:\xpdftest\xpdf下面
private String CONVERTOR_STORED_PATH = "c:\\xpdftest\\xpdf\\";
// 转换器的名称,默认为pdftotext
private String CONVERTOR_NAME = "pdftotext";
// 构造函数,参数为pdf文件的路径
public XpdfToText(String pdffile) throws IOException {
this.pdffile = new File(pdffile);
}
// 将pdf转为文本文档,参数为目标文件的路径
public void toTextFile(String targetfile) throws IOException {
toTextFile(targetfile, true);
}
// 将pdf转为文本文档,参数1为目标文件的路径,
// 参数2为true则表示使用PDF文件中的布局
public void toTextFile(String targetfile, boolean isLayout)
throws IOException {
String[] cmd = getCmd(new File(targetfile), isLayout);
Runtime.getRuntime().exec(cmd);
}
// 获取PDF转换器的路径
public String getCONVERTOR_STORED_PATH() {
return CONVERTOR_STORED_PATH;
}
// 设置PDF转换器的路径
public void setCONVERTOR_STORED_PATH(String path) {
if (!path.trim().endsWith("\\"))
path = path.trim() + "\\";
this.CONVERTOR_STORED_PATH = path;
}
// 解析命令行参数
private String[] getCmd(File targetfile, boolean isLayout) {
// 命令字符
String command = CONVERTOR_STORED_PATH + CONVERTOR_NAME;
// PDF文件的绝对路径
String source_absolutePath = pdffile.getAbsolutePath();
// 输出文本文件的绝对路径
String target_absolutePath = targetfile.getAbsolutePath();
// 保持原来的layout
String layout = "-layout";
// 设置编码方式
String encoding = "-enc";
String character = "GBK";
// 设置不打印任何消息和错误
String mistake = "-q";
// 页面之间不加入分页
String nopagebrk = "-nopgbrk";
// 如果isLayout为false,则设置不保持原来的layout
if (!isLayout)
layout = "";
return new String[] { command, layout, encoding, character, mistake,
nopagebrk, source_absolutePath, target_absolutePath };
}
}
TestXpdfToText.java
package pdfToText;
public class TestPdfToText {
public static void main(String[] args) {
String rootPath = "c:\\Nutch入门教程";
//pdf文件路径
String pdffile = rootPath + ".pdf";
//用xpdf生成的txt文件路径
String xpdfToTxtfile = rootPath + "_xpdf.txt";
//用pdfbox生成的txt文件路径
String pdfboxToTxtfile = rootPath + "_pdfbox.txt";
//XPDF
try{
long begin = System.currentTimeMillis();
XpdfToText xpToTxt = new XpdfToText(pdffile);
xpToTxt.toTextFile(xpdfToTxtfile);
long end = System.currentTimeMillis();
System.out.println("xpdf\t cost:\t" + (end - begin) + " ms");
}catch(Exception e){
e.printStackTrace();
}
}
}
3:运行:
运行后即可在C盘目录下看到转换后的txt
- 如何使用xpdf把本地磁盘上的pdf转化为txt
- 使用XPDF将PDF转换为HTML
- pdf转化为txt (PDFBox)
- pdf的换行转化为不换行的txt
- 如何把man手册内容转化为PDF
- 如何把pdf转化为word (含解锁码)
- 使用samba把整个linux文件系统映射为本地磁盘
- 免费实用的如何把pdf转换成txt教程
- 如何把pdf转换成txt格式的文件
- 把pdf文档转化为swf
- 如何将编辑好的TXT转换为PDF文件
- 如何把本地 PDF 文件添加到 iOS 的 iBooks
- 如何把word转化成pdf
- java - 使用itext把txt转换pdf
- xpdf的使用
- 如何快速的把日志输出到磁盘上
- XPdf实现pdf转txt格式方法实现
- 安装html5转化为pdf的python库pisa 安装matplotlab把数据转化为图形的python库
- float vs int
- GCDAsyncSOcket使用及其SSL/TLS双向认证的实现
- 03-如何对Memchached进行CRUD操作?
- 虐人的hd1001 Sum Problem
- pcl里面的点特征直方图(PFH)
- 如何使用xpdf把本地磁盘上的pdf转化为txt
- 反转链表
- Unity协程(Coroutine)原理深入剖析
- 别人犯错给自己的警醒(二):人取得成就之后很容易膨胀
- 一个简单的Python爬虫
- mysql面试必会基础(一)
- ssd/内存 基本知识
- MFC界面设计入门篇
- Android ION机制_HAL与vendor层共享内存_流程简介(1)