Convert Pdf To Image Using Python
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_fr
Solution 1:
I failed in python2 too, but succeeded in python3.
There's a same issue happened on an other library: TypeError: 'threadsafe_iter' object is not an iterator
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.
BTW, i have create a new issue to pdf2image team. TypeError: ThreadSafeGenerator object is not an iterator #133
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
Solution 2:
If you want to convert PDF to image you can try Python Ghostscript package:
pip install ghostscript
import ghostscript
import locale
defpdf2jpeg(pdf_input_path, jpeg_output_path):
args = ["pef2jpeg", # actual value doesn't matter"-dNOPAUSE",
"-sDEVICE=jpeg",
"-r144",
"-sOutputFile=" + jpeg_output_path,
pdf_input_path]
encoding = locale.getpreferredencoding()
args = [a.encode(encoding) for a in args]
ghostscript.Ghostscript(*args)
pdf2jpeg(
"...Fixate/ActiveState/pdf/a.pdf",
"...Fixate/ActiveState/pdf/a.jpeg",
)
Post a Comment for "Convert Pdf To Image Using Python"