Skip to content

Unable to get page count on Windows 11 with poppler 23.10.0 and pdf2image 1.17.0 #300

Description

@ZKHMao

Description

I encountered an error "Unable to get page count." when using the pdf2image library to process PDF files. Here are the detailed circumstances:

Environment Information

  • Operating System: Windows 11
  • Python Version: 3.13.2
  • pdf2image Version: 1.17.0
  • poppler Version: Release-23.10.0-0

Steps to Reproduce

  1. Install Python, pdf2image, and poppler with the above - mentioned versions, and add the bin directory of poppler to the system's PATH environment variable.
  2. Run the following Python code:
from pdf2image import convert_from_path

pdf_path = 'path/to/your/pdf/file.pdf'
images = convert_from_path(pdf_path)
  1. When the convert_from_path function is executed, the error "Unable to get page count." will be thrown.

Expected Result

The code should be able to read the PDF file normally and convert it into a list of images.

Actual Result

The code throws an error "Unable to get page count." and cannot continue the PDF conversion operation.

Error Message

Traceback (most recent call last):
  File "H:\Anaconda_envs\envs\LLM\Lib\site-packages\pdf2image\pdf2image.py", line 256, 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 "H:\4.IDESpace\LLM_S\pdfs\pdf2ImageTest.py", line 10, in <module>
    images = convert_from_path(r'H:\4.IDESpace\LLM_S\pdfs\testPDF.pdf')
  File "H:\Anaconda_envs\envs\LLM\Lib\site-packages\pdf2image\pdf2image.py", line 55, in convert_from_path
    page_count = _page_count(pdf_path, userpw, poppler_path=poppler_path)
  File "H:\Anaconda_envs\envs\LLM\Lib\site-packages\pdf2image\pdf2image.py", line 258, in _page_count
    raise PDFPageCountError('Unable to get page count. %s' % err.decode("utf8", "ignore"))
pdf2image.exceptions.PDFPageCountError: Unable to get page count. 

Additional Information

I've tried multiple different PDF files, and this error occurs every time. Meanwhile, I've confirmed that the installation path of poppler has been correctly configured in the system environment variables.

I hope to get help to solve this problem. Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions