Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to convert a PDF to PNG

with Img(filename='read1.pdf', resolution=300) as img:
    img.compression_quality = 99
    img.save(filename='read1.jpg')

But I am getting the following error.

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:Usersl-gunalanAppDataLocalContinuumanaconda3libsite-packageswand-0.4.4-py3.6.eggwandimage.py", line 2744, in __init__
  File "C:Usersl-gunalanAppDataLocalContinuumanaconda3libsite-packageswand-0.4.4-py3.6.eggwandimage.py", line 2822, in read
  File "C:Usersl-gunalanAppDataLocalContinuumanaconda3libsite-packageswand-0.4.4-py3.6.eggwand
esource.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:Usersl-gunalanAppDataLocalContinuumanaconda3libsite-packageswand-0.4.4-py3.6.eggwand
esource.py", line 232, in __del__
  File "C:Usersl-gunalanAppDataLocalContinuumanaconda3libsite-packageswand-0.4.4-py3.6.eggwandimage.py", line 2767, in destroy
TypeError: object of type 'NoneType' has no len()

I really don't know why I get NoneType error here. I have tried other methods too but I am getting the same error. Is there anything wrong with the PDF and How can I find that? Any suggestion on how to rectify this error?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
171 views
Welcome To Ask or Share your Answers For Others

1 Answer

I thought you were trying to convert it to png - why did you save it as jpg?

Also, why not use this instead?:

Use pdf2image

pip install pdf2image

Then use it to get the image from the pdf

from pdf2image import convert_from_path
pages = convert_from_path('pdf_file', 500)

for page in pages:
    page.save('out.png', 'png')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...