在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.