我正在尝试使用 pdf2image,但出现此错误

时间:2021-02-15 12:54:18

标签: python poppler

Traceback (most recent call last):
  File "C:\Users\Balmeet\PycharmProjects\text&checkBox\venv\lib\site-packages\pdf2image\pdf2image.py", line 441, in pdfinfo_from_path
    proc = Popen(command, env=env, stdout=PIPE, stderr=PIPE)
  File "C:\Users\Balmeet\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 756, in __init__
    restore_signals, start_new_session)
  File "C:\Users\Balmeet\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 1155, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/Balmeet/PycharmProjects/tables/final.py", line 470, in <module>
    pdf2img2.convert_to_image(pdf_file)
  File "C:\Users\Balmeet\PycharmProjects\tables\pdf2img2.py", line 42, in convert_to_image
    pages = convert_from_path(pdf_file, 600)
  File "C:\Users\Balmeet\PycharmProjects\text&checkBox\venv\lib\site-packages\pdf2image\pdf2image.py", line 97, in convert_from_path
    page_count = pdfinfo_from_path(pdf_path, userpw, poppler_path=poppler_path)["Pages"]
  File "C:\Users\Balmeet\PycharmProjects\text&checkBox\venv\lib\site-packages\pdf2image\pdf2image.py", line 468, in pdfinfo_from_path
    "Unable to get page count. Is poppler installed and in PATH?"
pdf2image.exceptions.PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?

我已按照类似帖子中提到的步骤操作并为 poppler 设置了路径,但仍然出现此错误 提前致谢:)

1 个答案:

答案 0 :(得分:1)

下载 Poppler 并将其保存在您有脚本的文件夹中,然后尝试执行以下操作。

from pdf2image import convert_from_path

pages = convert_from_path(f'dummy.pdf', poppler_path='poppler-20.12.1\\bin')
for page in pages:
    n = 1
    page.save(f'page{n}.png', 'PNG')
    n += 1

我已经对此进行了测试,并将 pdf 文件转换为图像。