When I did a code to convert PDF files to JPG images, but I have met an issue.Sometimes the .pdf file work well.But sometimes there is an error,the first temp file can't read.I checked the temp folder.When it works well, all the created temp file be deleted successfully. And when the error happens,only the first temp file is deleted. I can't resolve it.Anyone can fix?
code:
from wand.image import Image
with open("C:\software\1234.pdf",'rb') as f: image_binary = f.read()
f.close() with Image(blob=image_binary,resolution=400) as img:
Traceback (most recent call last): File "C:\xxxx\eclipse-workspace\test\123\pdf2jpg.py", line 16, in with Image(blob=image_binary,resolution=400) as img: File "C:\xxxx\AppData\Local\Programs\Python\Python37\lib\site-packages\wand\image.py", line 2742, in init self.read(blob=blob, resolution=resolution) File "C:\xxxx\AppData\Local\Programs\Python\Python37\lib\site-packages\wand\image.py", line 2822, in read self.raise_exception() File "C:\xxxx\AppData\Local\Programs\Python\Python37\lib\site-packages\wand\resource.py", line 222, in raise_exception raise e wand.exceptions.CorruptImageError: unable to read image data `C:/xxxx/AppData/Local/Temp/magick-22200zyw89Zpq8IFJ1' @ error/pnm.c/ReadPNMImage/1344 Exception ignored in: Traceback (most recent call last): File "C:\xxxx\AppData\Local\Programs\Python\Python37\lib\site-packages\wand\resource.py", line 232, in del File "C:\xxxx\AppData\Local\Programs\Python\Python37\lib\site-packages\wand\image.py", line 2767, in destroy TypeError: object of type 'NoneType' has no len()