python学习:pdf 转 image 的方法
pdf 转 image 的方法
安装 poppler
Poppler is a PDF rendering library based on the xpdf-3.0 code base.
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
brew install poppler
根据上面的代码,
.zprofile
内容如下
$ cat .zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
安装 pdf2image
pip install pdf2image
用法
from pdf2image import convert_from_path
images = convert_from_path('581.pdf')
for i in range(len(images)):
# Save pages as images in the pdf
images[i].save(f'image_{i+1}.png', 'PNG')