Unable to convert pdf to image using pdf2image
See original GitHub issuedef convert(files): pages = convert_from_path(files, 500) out_file="ConvertedToImage.jpg" for page in pages: page.save(out_file, 'JPEG') return out_file
Above is the code snippet of the function. I am getting a following error while converting the pdf to image: Traceback (most recent call last): File “C:\Users\DEll\AppData\Local\Programs\Python\Python36\lib\site-packages\pdf2image\pdf2image.py”, line 190, in _page_count return int(re.search(r’Pages:\s+(\d+)', out.decode(“utf8”, “ignore”)).group(1)) AttributeError: ‘NoneType’ object has no attribute ‘group’
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File “final.py”, line 11, in <module> divide.send(in_file) File “C:\Users\DEll\Downloads\Interns Py\divide.py”, line 123, in send toIm=convert(in_file) File “C:\Users\DEll\Downloads\Interns Py\divide.py”, line 86, in convert pages = convert_from_path(files, 500) File “C:\Users\DEll\AppData\Local\Programs\Python\Python36\lib\site-packages\pdf2image\pdf2image.py”, line 46, in convert_from_path page_count = _page_count(pdf_path, userpw) File “C:\Users\DEll\AppData\Local\Programs\Python\Python36\lib\site-packages\pdf2image\pdf2image.py”, line 192, in _page_count raise PDFPageCountError(‘Unable to get page count. %s’ % err.decode(“utf8”, “ignore”)) pdf2image.exceptions.PDFPageCountError: Unable to get page count. I/O Error: Couldn’t open file ‘pdfinfo’: No error.
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (5 by maintainers)
Top GitHub Comments
I got insight from https://github.com/Belval/pdf2image/blob/master/README.md
Below is my code for doing something similar and made use of convert_from_bytes() instead of convert_from_path() , then fed the full file path to the function using r’string’ for raw string and a forward slash . Taking those into consideration I eliminated some errors like :
FileNotFoundError: [Errno 2] No such file or directory: ‘\Desktop\companyprofile.pdf’ UnicodeDecodeError: ‘charmap’ codec can’t decode byte 0x8d in position 1159: character maps to <undefined> pdf2image.exceptions.PDFPageCountError: Unable to get page count. I/O Error: Couldn’t open file ‘companyprofile.pdf’: No error.
from pdf2image import convert_from_path,convert_from_bytes from pdf2image.exceptions import ( PDFInfoNotInstalledError, PDFPageCountError, PDFSyntaxError )
images = convert_from_bytes(open(r’/Users/Robotnic/Desktop/companyprofile.pdf’,‘rb’).read())
for i, image in enumerate(images): fname = “image” + str(i) + “.png” image.save(fname, “PNG”)
I think you should be able to relate the code to yours
I’m also able to open pdfinfo but still getting error. Kindly suggest. PDFinfo
Error