【发布时间】:2021-08-19 06:10:14
【问题描述】:
我知道有很多库可以从 PDF 中提取文本。具体来说,我在使用 pymupdf 时遇到了一些困难。
从这里的文档:https://pymupdf.readthedocs.io/en/latest/app4.html#sequencetypes
我希望使用select() 选择一个页面间隔,然后使用getText() 这是我正在使用的文档linear_regression.pdf
import fitz
s = [1, 2]
doc = fitz.open('linear_regression.pdf')
selection = doc.select(s)
text = selection.getText(s)
但我收到此错误:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-23-c05917f260e7> in <module>()
6 # print(selection)
7 # text = doc.get_page_text(3, "text")
----> 8 text = selection.getText(s)
9 text
AttributeError: 'NoneType' object has no attribute 'getText'
所以我假设 select() 没有被正确使用
非常感谢
【问题讨论】:
-
问题是
doc.select(s)正在返回None。但是,您没有在此处定义doc,因此不清楚这是为什么。请编辑您的问题以提供minimal, reproducible example。 -
谢谢@Kraigolas,我根据您的反馈编辑了帖子