在Python中将PDF文件转换为文本文件 [英] Converting a PDF file to a Text file in Python

查看:88
本文介绍了在Python中将PDF文件转换为文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经花了几天的时间+研究互联网如何从pdf文件中获取特定信息.

I've been on it for several days + researching the internet on how to get specific information from a pdf file.

最终,我能够使用Python从文本文件(通过转到 PDF文件-----> File ------> Save as Text 创建的文本文件)中获取所有信息. >).

Eventually I was able to fetch all information using Python from a text file(which I created by going to the PDF file -----> File ------> Save as Text).

问题是我如何让Python完成这些任务(转到PDF文件(将其打开-非常容易打开(文件路径")),在菜单中单击文件",然后将文件另存为文本文件放在同一目录中.

The question is how do I get Python to accomplish those tasks(Going to the PDF file(opening it - is quite easy open("file path"), clicking on File in the menu, and then saving the file as a text file in the same directory).

请清楚一点,我不需要pdfminer或pypdf库,因为我已经使用同一文件提取了信息(在将其手动转换为txt后)

Just to be clear, I do not require the pdfminer or pypdf libraries as I have already extracted the information with the same file(after converting it manually to txt)

推荐答案

您可以使用pdftotext.exe,您可以从 http://www.foolabs.com/xpdf/download.html ,然后通过Python在pdf文件上执行它:

You could use pdftotext.exe that you can download from http://www.foolabs.com/xpdf/download.html and then execute it on your pdf files via Python:

import os
import glob
import subprocess

#remember to put your pdftotxt.exe to the folder with your pdf files 
for filename in glob.glob(os.getcwd() + '\\*.pdf'):
    subprocess.call([os.getcwd() + '\\pdftotext', filename, filename[0:-4]+".txt"])

至少它对我的一个项目有效.

At least it worked for one of my projects.

这篇关于在Python中将PDF文件转换为文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆