pdf2image.exceptions.PDFPageCountError: Unable to get page count. error

Hello I am working on a project(converting pdf to jpeg images), I am using the pdf2img module in python for the same.But I am getting an error here:

 images=convert_from_path(filename,poppler_path=r'C:\Program Files\Library\bin')

the error which I used to get in the beginning was poppler was not in path, but after correcting it now I am getting the error:

pdf2image.exceptions.PDFPageCountError: Unable to get page count.

Kindly help me to resolve this issue,

from pdf2image import*

the module I used is pdf2image

1

6 Answers

I had the same issue and solved it by installing Microsoft Visual C++ Redistributable which was missing from my computer (download here). You can check that the program pdfinfo.exe works fine, by running it from your console (the program is located in the Library/bin folder of poppler). If it fails, you will get the real error, otherwise it's caught and silenced by pdf2image.py telling you it could not get the page count.

from pdf2image import convert_from_path
images=convert_from_path("pdf_file_path_with_name",poppler_path="")
for i in range(len(images)): images[i].save('image_name'+ str(i) +'.jpg', 'JPEG')

Haw, I also encountered this problem. This problem occurs if the script is executed on IDE, If you execute the script in the folder, There will be no problem. Maybe it's the execution path.

The reason could be if your PDF file path is not proper or broken. In my problem I solved this by changing quotes to single quote in file path. Maybe this is something related with encoding.

If you dive into pdf2image code, you'll see that this is happening after pdfinfo.exe is called on your pdf file. Try running it manually and you'll see what is happening there and if there any errors while running pdfinfo.exe.

I had this error: "The code execution cannot proceed because freetype.dll was not found...". So I just found freetype.dll in my Anaconda path (I used Anaconda to install pdf2image on Win10) and added this path to PATH environment variable, so it would be found. This was the only problem and I've got my images from pdf.

I encountered the same error but I correct my file path after that the issue will be resolved.

You Might Also Like