作为使用Poppler
进行PDF渲染和转换的一部分,我有以下代码,但执行代码时出现了以下错误。
错误消息:pdf2image.exceptions.PDFInfoNotInstalledError:无法以获取页数。poppler是否已安装并在PATH中?
我添加了Poppler路径作为环境变量,但错误仍然存在。
import tempfile,os
with tempfile.TemporaryDirectory() as path:
images_from_path = convert_from_path("C:\Users\mehak\OneDrive\Desktop\iffco.pdf")
index = 1
for image in images_from_path:
image.save("C:\Users\mehak\OneDrive\Desktop" + str(index) + ".jpg")
index += 1```
```Traceback (most recent call last):
File "C:UsersmehakAppDataLocalProgramsPythonPython37libsite-packagespdf2imagepdf2image.py", line 355, in _page_count
proc = Popen(command, env=env, stdout=PIPE, stderr=PIPE)
File "C:UsersmehakAppDataLocalProgramsPythonPython37libsubprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "C:UsersmehakAppDataLocalProgramsPythonPython37libsubprocess.py", line 1178, 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 "testing_ocrpdf.py", line 7, in <module>
images_from_path = convert_from_path('D:\iffco.pdf')
File "C:UsersmehakAppDataLocalProgramsPythonPython37libsite-packagespdf2imagepdf2image.py", line 82, in convert_from_path
page_count = _page_count(pdf_path, userpw, poppler_path=poppler_path)
File "C:UsersmehakAppDataLocalProgramsPythonPython37libsite-packagespdf2imagepdf2image.py", line 360, in _page_count
"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?```
我按照这些步骤包括了path,它按预期工作。
新建或编辑此变量并提及您的路径。
您可以在此处找到解决方案。
pip install pdf2image
您只执行了上面的步骤。
以下步骤取决于您的计算机系统。
窗口
Windows用户将不得不为Windows构建或下载poppler。我推荐最新的@oschwartz10612版本。然后,您必须将bin/
文件夹添加到PATH或在convert_from_path
中使用poppler_path = r"C:pathtopoppler-xxbin" as an argument
。
Mac
Mac用户将不得不安装poppler。
使用Brew:安装
brew install poppler
Linux
大多数发行版附带pdftoppm
和pdftocairo
。如果未安装,请参阅软件包管理器以安装poppler-utils
。
平台独立器(使用conda
(安装poppler:conda install -c conda-forge poppler
安装pdf2image:pip install pdf2image