from pdfminer.pdfinterp import PDFResourceManager, process_pdf
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
import threading, os class PdfThread(threading.Thread):
def __init__(self, in_queue, doc_txt_dir):
threading.Thread.__init__(self)
self.in_queue = in_queue
self.doc_txt_dir = doc_txt_dir def run(self):
while True:
try:
codec = 'utf-8'
in_fname = self.in_queue.get()
rsrc = PDFResourceManager(caching = True)
base_name = os.path.basename(in_fname)
out_file = os.path.join(self.doc_txt_dir, base_name[0:base_name.rfind(".")] + ".txt")
outfp = file(out_file, 'w')
laparams = LAParams() #加上此参数可保留原pdf中的字符间空格
device = TextConverter(rsrc, outfp, codec=codec, laparams=laparams)
fp = file(in_fname, 'rb')
caching = True
pagenos = set()
process_pdf(rsrc, device, fp, pagenos, maxpages=0, password='',caching=caching, check_extractable=True)
fp.close()
device.close()
outfp.close()
print "have convert pdf file %s to file %s" %(in_fname, out_file)
finally:
self.in_queue.task_done()
#TagExtractor

pdfminer的TextConverter得到文件字符无空格解决方法的更多相关文章

  1. Ant编译utf-8非法字符:/65279 解决方法

    原文链接:http://blog.csdn.net/xiyuan1999/article/details/5989336   Ant编译utf-8非法字符:/65279 解决方法   使用ant编译j ...

  2. MyEclipse中点击Deploy MyEclipse J2EE Project to Server无响应解决方法

    问题: MyEclipse中点击Deploy MyEclipse J2EE Project to Server无响应 解决方法: 如果工作空间的问题,那么需要删除你工作空间的一个文件就可以解决了.这个 ...

  3. JCIFS读取远程服务器文件过慢的解决方法

    JCIFS读取远程服务器文件过慢的解决方法 发表于3年前(2013-07-12 11:23)   阅读(1174) | 评论(0) // 我要收藏"; var favor_del = &qu ...

  4. Log4Net 生成多个文件、文件名累加解决方法

    Log4Net 生成多个文件.文件名累加解决方法 项目中的WCF服务里采用Log4Net用来记录异常日志,但部署后,生成的日志会出现多个累加文件,如下图: WCF是寄宿在IIS上,包含了5个SVC服务 ...

  5. EXCEL词典(xllex.dll)文件丢失或损坏解决方法

    EXCEL词典(xllex.dll)文件丢失或损坏解决方法     1● 问题   2● 解决 fail 3● 方法2   regsvr32 xllex.dll     4● 方法3 启动server ...

  6. webstorm无法显示左边文件夹目录的解决方法

    webstorm无法显示左边文件夹目录的解决方法 方法一 view-->Tool Windows-->Project 就可以显示或者关闭 方法二 1.删除webstorm的配置文件夹 2. ...

  7. svn新建文件不能提交的解决方法

    svn新建文件不能提交的解决方法 在当前新建文件的目录下,右键空白处: 选择Properties 找到所有有ignore字眼的属性,查看这个属性的继承目录(inherited from),入我的是cl ...

  8. php Yaf_Loader::import引入文件报错的解决方法

    php Yaf_Loader::import引入文件报错的解决方法 改下配置文件就行<pre>yaf.use_spl_autoload=1</pre> 也可以PHP动态修改 毕 ...

  9. Android studio R文件丢失或错误解决方法

    android studio中有时引用资源会出现R文件丢失或报错,大多数情况下是由于引入资源时R文件没有及时更新造成的 (在代码没有错误或资源引用没有错误的前提下) 注意:资源文件的文件名必须小写,即 ...

随机推荐

  1. T-SQL基础 (存储过程,触发器|| 笔记0808)

    一:存储过程 1.使用EXEC 调用存储过程 2.系统存储过程是以SP_开头,SP_ProcedureName.:例子:EXEC sp_columns TableName 查看列信息   扩展存储过程 ...

  2. MongoDB 2.6.x 的安装部署

    1. 下载mongodb 2.6.x版本的zip包,在D盘创建目录MongoDB,解压缩到D:\MongoDB目录. 创建数据库目录D:\MongoDB\data,接下来打开命令行窗口,切换到D:\M ...

  3. 20160410javaweb之JDBC---DBUtils框架

    DBUtils 1.DbUtils 工具类 2.QueryRunner -- 两行代码搞定增删改查 (1)QueryRunner() --需要控制事务时,使用这组方法 int update(Conne ...

  4. C#中 字符串的处理

    3.字符串 1).字符串的不可变性 当你给一个字符串重新赋值之后,老值并没有销毁,而是重新开辟一块空间存储新值. 当程序结束后,GC扫描整个内存,如果发现有的空间没有被指向,则立即把它销毁. 2).我 ...

  5. ibatis调存储过程返回游标

    http://blog.sina.com.cn/s/blog_6f3ca78f01010pmj.html iBatic调用与JAVA调用很类似,只是JAVA把参数的注册放到了类里面,而iBatis把参 ...

  6. 暑假集训(2)第一弹 -----Is It A Tree?(Poj308)

    A - Is It A Tree? Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:10000KB  ...

  7. ios 64位下编译webrtc的libvpx库出现错误Bad cputype for object file.Currently only tested for CPU_TYPE_x86_64

    diff --git a/libvpx.gyp b/libvpx.gypindex 4f8cb2b..4eb6866 100644--- a/libvpx.gyp+++ b/libvpx.gyp@@ ...

  8. ECMA5.1中关于encodeURI,decodeURI 和encodeComponentURI,decodeComponentURI的区别

    The encodeURI and decodeURI functions are intended to work with complete URIs; theyassume that any r ...

  9. ubuntu intelliJ IDEA 12.1.4 安装

    1 php插件 http://plugins.jetbrains.com/plugin/?id=6610 把插件下载到一个目录下,如果插件不兼容,多试几个版本! 2 打开ide, FILE -> ...

  10. C# 在SQLite数据库中存储图像 z

    C# 在SQLite数据库中存储图像 更多 0 C# SQLite   建表语句 CREATE TABLE [ImageStore]([ImageStore_Id] INTEGER NOT NULL ...