python - 我正在尝试使用 pdf2image 但我收到此错误
问题描述
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 设置路径,但仍然收到此错误 ,谢谢:)
解决方案
下载 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文件转换为图像。
推荐阅读
- javascript - 如何在更改的 Google 工作表数据上最后加载并使用脚本以 PDF 格式发送电子邮件
- r - R错误:新列会在现有列之后留下孔
- html - Angular 获取 Json 对象并用 HTML 显示它
- android-studio - 从 android studio 连接到 localhost
- python - 如何将数据框转换为字典列表
- sql-server - 是否可以创建额外的 sp_user_counter
- asterisk - 星号:进入队列时向呼叫者播放消息
- python - Pytorch 数学计算(只能将一个元素张量转换为 Python 标量)
- c++ - 为什么 typedef 一个类作为 C++ 中的指针
- swiftui - 将 SwiftUI ColorPicker 限制为仅在亮/暗模式下工作的颜色