pdf转换成jpg python_使用Python将PDF转换为图像

1586010002-jmsa.png

I am trying to convert a pdf file to image file for this in my ubuntu server i have installed:

python2.7

poppler-utils

pdf2image==1.12.1

My code:

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())

OUTPUT

When I am using the function "convert_from_path"

Traceback (most recent call last):

File "", line 1, in

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

When I am using the function "convert_from_bytes"

Traceback (most recent call last):

File "", line 2, in

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

I have reinstalled all my utilities then i am facing these problems.

解决方案

I failed in python2 too, but succeeded in python3.

As they said, it's a python 2 vs 3 issue, caused by next() function.

If modify __next__() -> next() in file/home/***/.local/lib/python2.7/site-packages/pdf2image/generators.py , it will run successful in py2.

Additional

pdf2image readme said it's a python (3.5+) module.

pdf2image v1.7.1 work on py27. try it by pip install pdf2image==1.7.1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值