question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to convert pdf to image using pdf2image

See original GitHub issue

def 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:closed
  • Created 5 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

9reactions
vicrobotniccommented, Dec 14, 2019

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

2reactions
sachidanandagiricommented, Apr 3, 2021

I’m also able to open pdfinfo but still getting error. Kindly suggest. PDFinfo image

Error

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Converting PDF to Image with pdf2image does not work
The error that I get: pdf2image.exceptions.PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH? How can ...
Read more >
Reference — pdf2image latest documentation
The converted images will be written there to save system memory. ... which is part of poppler-utils, was unable to get the page...
Read more >
pdf2image - PyPI
A wrapper around the pdftoppm and pdftocairo command line tools to convert PDF to a PIL Image list.
Read more >
Frequently Asked Questions for PDF2Image | PDFTron CLI
How do I convert PDF to JPEG, PNG, TIF or some other image format? ... If PDF2Image fails to allocate enough memory, you...
Read more >
How to convert PDF to JPG using Adobe Acrobat
Click the Export PDF tool in the right pane. Choose Image as your export format, and then choose JPEG.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found