问题描述
我正在尝试提取使用Python
的PDF文件.
I'm trying to extract the text included in this PDF file using Python
.
I'm using the PyPDF2 module, and have the following script:
import PyPDF2
pdf_file = open('sample.pdf')
read_pdf = PyPDF2.PdfFileReader(pdf_file)
number_of_pages = read_pdf.getNumPages()
page = read_pdf.getPage(0)
page_content = page.extractText()
print page_content
运行代码时,得到以下输出,该输出与PDF文档中包含的输出不同:
When I run the code, I get the following output which is different from that included in the PDF document:
!"#$%#$%&%$&'()*%+,-%./01'*23%4
5'%1$#26%3/%7/))/8%&)/26%8#3"%3"*%313/9#&)
%
如何提取PDF文档中的文本?
How can I extract the text as is in the PDF document?
推荐答案
正在寻找适用于python 3.x和Windows的简单解决方案.似乎没有来自 textract 的支持,这很不幸,但是如果您正在寻找对于Windows/python 3的简单解决方案,请检出 tika 程序包,对于阅读pdf来说确实很简单.
Was looking for a simple solution to use for python 3.x and windows. There doesn't seem to be support from textract, which is unfortunate, but if you are looking for a simple solution for windows/python 3 checkout the tika package, really straight forward for reading pdfs.
from tika import parser
raw = parser.from_file('sample.pdf')
print(raw['content'])
这篇关于如何从PDF文件中提取文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!