我正在尝试将PDF转换为PNG
with Img(filename='read1.pdf', resolution=300) as img:
img.compression_quality = 99
img.save(filename='read1.jpg')
但是我遇到了以下错误。
Traceback (most recent call last):
File "C:/Users/l-gunalan/PycharmProjects/ocr/chech.py", line 4, in <module>
with Img(filename='read1.pdf', resolution=300) as img:
File "C:\Users\l-gunalan\AppData\Local\Continuum\anaconda3\lib\site-packages\wand-0.4.4-py3.6.egg\wand\image.py", line 2744, in __init__
File "C:\Users\l-gunalan\AppData\Local\Continuum\anaconda3\lib\site-packages\wand-0.4.4-py3.6.egg\wand\image.py", line 2822, in read
File "C:\Users\l-gunalan\AppData\Local\Continuum\anaconda3\lib\site-packages\wand-0.4.4-py3.6.egg\wand\resource.py", line 222, in raise_exception
wand.exceptions.DelegateError: PDFDelegateFailed `Unrecoverable error: rangecheck in .setuserparams
Operand stack:
--nostringval-- --nostringval-- --nostringval--
START 0 2588256 1247365 1476808 191920 true 1138 5 <3>
END PROCS 0 2588256 1258664 1476808 193304 true 1137 5 <3>
gs_std_e.ps 0 2608352 1264725 1476808 194688 true 1137 5 <6>
gs_il1_e.ps 0 2608352 1266914 1476808 194688 true 1137 5 <9>
END FONTDIR/ENCS 0 2608352 1267092 1476808 194688 true 1137 5 <15>
END DEVS 0 2611856 1274124 1476808 194688 true 1137 5 <15>
END STATD 0 2611856 1281294 1496904 199640 true 1137 5 <39>
END GS_FONTS 0 2652048 1312194 1496904 199640 true 1138 5 <45>
END BASIC COLOR 0 2652048 1318761 1496904 199640 true 1136 5 <48>
END LEVEL 1 COLOR 0 2652048 1320495 1496904 199640 true 1136 5 <51>
END IMAGE 0 2672144 1327155 1496904 199640 true 1136 5 <54>
gs_btokn.ps 0 2672144 1330603 1496904 199640 true 995 4 <57>
gs_dps1.ps 0 2672144 1331954 1496904 199640 true 995 4 <57>
gs_dps2.ps 0 2672144 1333967 1496904 199640 true 995 4 <57>
gs_type1.ps 16 2672144 1335499 1496904 199640 true 995 4 <57>
While reading gs_lev2.ps:
%%[ Error: invalidaccess; OffendingCommand: put ]%%
START 333850 2746856 1404704 1496904 201896 true 999 7 <92>
END PROCS 333850 2746856 1415987 1496904 203280 true 997 7 <92>
gs_std_e.ps 333850 2766952 1422048 1496904 204664 true 997 7 <95>
gs_il1_e.ps 333850 2766952 1424237 1496904 204664 true 997 7 <98>
END FONTDIR/ENCS 333850 2766952 1424415 1496904 204664 true 997 7 <104>
END DEVS 333850 2770456 1431447 1496904 204664 true 997 7 <104>
END STATD 333850 2770456 1438681 1496904 206288 true 997 7 <128>
END GS_FONTS 333850 2800400 1467839 1496904 206288 true 997 7 <134>
END BASIC COLOR 333850 2820496 1477734 1496904 206288 true 995 7 <137>
END LEVEL 1 COLOR 333850 2820496 1479468 1496904 206288 true 995 7 <140>
END IMAGE 333850 2820496 1482776 1496904 206288 true 995 7 <143>
gs_btokn.ps 333850 2820496 1486224 1496904 206288 true 995 7 <146>
gs_dps1.ps 333850 2820496 1487575 1496904 206288 true 995 7 <146>
gs_dps2.ps 333850 2820496 1489588 1496904 206288 true 995 7 <146>
gs_type1.ps 333850 2840592 1494496 1496904 206288 true 995 7 <146>
While reading gs_lev2.ps:
%%[ Error: invalidaccess; OffendingCommand: put ]%%
' @ error/pdf.c/ReadPDFImage/811
Exception ignored in: <bound method Resource.__del__ of <wand.image.Image: (empty)>>
Traceback (most recent call last):
File "C:\Users\l-gunalan\AppData\Local\Continuum\anaconda3\lib\site-packages\wand-0.4.4-py3.6.egg\wand\resource.py", line 232, in __del__
File "C:\Users\l-gunalan\AppData\Local\Continuum\anaconda3\lib\site-packages\wand-0.4.4-py3.6.egg\wand\image.py", line 2767, in destroy
TypeError: object of type 'NoneType' has no len()
我真的不知道为什么我在这里出现NoneType错误。我也尝试了其他方法,但是遇到了同样的错误。 PDF有什么问题吗?如何找到呢? 有关如何纠正此错误的任何建议?
答案 0 :(得分:1)
我以为您正在尝试将其转换为png-为什么将其另存为 jpg?
还为什么不使用它呢?:
使用pdf2image
pip install pdf2image
然后使用它从pdf获取图像
from pdf2image import convert_from_path
pages = convert_from_path('pdf_file', 500)
for page in pages:
page.save('out.png', 'png')