【发布时间】:2018-07-13 09:30:19
【问题描述】:
我的应用程序运行了几次,然后在每个 pdf 上都出现错误。这是我收到的错误:
Exception TypeError: TypeError("object of type 'NoneType' has no len()",) in <bound method Image.__del__ of <wand.image.Image: (empty)>> ignored
这是我使用的功能:
def read_pdf(file):
pre, ext = os.path.splitext(file)
filename = pre + '.png'
with Image(filename=file, resolution=200) as pdf:
amount_of_pages = len(pdf.sequence)
image = Image(
width=pdf.width,
height=pdf.height * amount_of_pages
)
for i in range(0, amount_of_pages):
image.composite(
pdf.sequence[i],
top=pdf.height * i,
left=0
)
image.compression_quality = 100
image.save(filename=filename)
logging.info('Opened and saved pdf to image: \'' + file + '\'.')
return filename
此函数将正确地将 pdf 转换为图像,但在两三次之后,它每次都会崩溃并抛出该异常。如果我重新启动 python 脚本,它会再次运行几次。
【问题讨论】: