【发布时间】:2020-06-27 06:54:04
【问题描述】:
我正在尝试在我安装的 ubuntu 服务器中将 pdf 文件转换为图像文件:
- python2.7
- poppler-utils
- pdf2image==1.12.1
我的代码:
from pdf2image import convert_from_path, convert_from_bytes
images = convert_from_path("/home/user/pdf_file.pdf")
# OR
with open("/home/user/pdf_file.pdf") as pdf:
images = convert_from_bytes(pdf.read())
输出
当我使用函数“convert_from_path”时
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pdf2image/pdf2image.py", line 143, in convert_from_path
thread_output_file = next(output_file)
TypeError: ThreadSafeGenerator object is not an iterator
当我使用“convert_from_bytes”函数时
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/usr/local/lib/python2.7/dist-packages/pdf2image/pdf2image.py", line 268, in convert_from_bytes
paths_only=paths_only,
File "/usr/local/lib/python2.7/dist-packages/pdf2image/pdf2image.py", line 143, in convert_from_path
thread_output_file = next(output_file)
TypeError: ThreadSafeGenerator object is not an iterator
我已经重新安装了所有实用程序,然后我面临这些问题。
【问题讨论】:
-
来自 pip pypi.org/project/pdf2image ,似乎不支持 Python 2.7。它清楚地说明了一个 python (3.5+) 模块,它包装了 pdftoppm 和 pdftocairo 以将 PDF 转换为 1.12.1 版的 PIL Image 对象
标签: python image pdf typeerror converters