pdf 文件中的文本是文本格式,不是扫描的。PDFMiner不支持python3,有没有其他解决方案?
问问题
3003 次
3 回答
3
还有 pdfminer2 fork,支持 python 3.4,可通过 pip3 获得。 https://github.com/metachris/pdfminer
这个线程帮助我将一些东西拼凑在一起。
from urllib.request import urlopen
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
from pdfminer.pdfpage import PDFPage
from io import StringIO, BytesIO
def readPDF(pdfFile):
rsrcmgr = PDFResourceManager()
retstr = StringIO()
codec = 'utf-8'
laparams = LAParams()
device = TextConverter(rsrcmgr, retstr, codec=codec, laparams=laparams)
interpreter = PDFPageInterpreter(rsrcmgr, device)
password = ""
maxpages = 0
caching = True
pagenos=set()
for page in PDFPage.get_pages(pdfFile, pagenos, maxpages=maxpages, password=password,caching=caching, check_extractable=True):
interpreter.process_page(page)
device.close()
textstr = retstr.getvalue()
retstr.close()
return textstr
if __name__ == "__main__":
#scrape = open("../warandpeace/chapter1.pdf", 'rb') # for local files
scrape = urlopen("http://pythonscraping.com/pages/warandpeace/chapter1.pdf") # for external files
pdfFile = BytesIO(scrape.read())
outputString = readPDF(pdfFile)
print(outputString)
pdfFile.close()
于 2016-02-05T13:30:20.863 回答
1
对于 python3,您可以下载 pdfminer 为:
python -m pip install pdfminer.six
于 2018-10-09T08:53:42.863 回答
0
tika
对我来说效果最好。PyPDF2
如果我说它比and更好,那不会错。pdfminer
这使得将 pdf 中的每一行提取到一个列表中变得非常容易。您可以通过pip install tika
And 安装它,使用以下代码:
from tika import parser
rawText = parser.from_file(path_to_pdf)
rawList = rawText['content'].splitlines()
print(rawList)
于 2019-06-20T08:07:36.837 回答