Python 将pdf转成图片的方法
作者:IT_xiao小巫 时间:2021-11-14 09:16:33
本篇文章记录如何使用python将pdf文件切分成一张一张图片,包括环境配置、版本兼容问题。
环境配置(mac)
安装ImageMagick
brew install imagemagick
这里有个坑,brew安装都是7.x版本,使用wand时会出错,需要你安装6.x版本。
解决办法:
1.安装6.x版本
brew install imagemagick@6
2.取消链接7.x版本
brew unlink imagemagick
Unlinking /usr/local/Cellar/imagemagick/7.0.7-4… 71 symlinks removed
3.强制链接6.x版本
brew link imagemagick@6 --force
Linking /usr/local/Cellar/imagemagick@6/6.9.9-15… 75 symlinks created
4.export环境变量
echo 'export PATH="/usr/local/opt/imagemagick@6/bin:$PATH"' >> ~/.bash_profile
ok,以上解决imagemagick版本问题。
安装gs
必须安装gs,否则pdf无法转换。
brew install gs
安装wand
pip3 install wand
我这里使用的是python3,所以需要用pip3.
代码实现
from wand.image import Image
def convert_pdf_to_jpg(filename):
with Image(filename=filename) as img :
print('pages = ', len(img.sequence))
with img.convert('jpeg') as converted:
converted.save(filename='image/page.jpeg')
效果
笔者将一本书四百多页都转出来了,大家也可以去试下啦。
来源:https://blog.csdn.net/wwj_748/article/details/78135879
标签:pdf,转成,图片,Python
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
HTTP 错误 500.100 - 内部服务器错误 - ASP 错误
2008-09-12 13:07:00
Python+OpenCV 实现简单的高斯滤波(推荐)
2021-07-18 20:31:26
![](https://img.aspxhome.com/file/2023/6/88936_0s.png)
Python实现生活常识解答机器人
2021-06-22 14:34:36
![](https://img.aspxhome.com/file/2023/6/70726_0s.png)
Python import自定义模块方法
2022-08-23 06:57:27
能否用显示/隐藏层来控制FLASH播放与停止
2008-10-27 14:08:00
使用Python实现毫秒级抢单功能
2022-10-17 18:46:16
![](https://img.aspxhome.com/file/2023/3/109583_0s.png)
浅析python 中大括号中括号小括号的区分
2021-06-15 15:14:16
Python3 replace()函数使用方法
2023-07-21 22:25:13
python多进程中的内存复制(实例讲解)
2022-01-20 23:34:46
![](https://img.aspxhome.com/file/2023/0/107030_0s.jpg)
Python matplotlib可视化绘图详解
2021-11-11 12:03:26
![](https://img.aspxhome.com/file/2023/0/78480_0s.png)
关于Python dict存中文字符dumps()的问题
2022-08-22 17:53:17
![](https://img.aspxhome.com/file/2023/7/79507_0s.png)
Python 使用类写装饰器的小技巧
2022-09-16 05:54:08
Matplotlib 3D 绘制小红花原理
2022-11-23 11:53:08
![](https://img.aspxhome.com/file/2023/1/88001_0s.png)
Python基于callable函数检测对象是否可被调用
2022-01-07 20:12:38
为MySQL提权简单方法
2009-08-29 15:21:00
关于浮动的前世今生
2009-08-19 18:51:00
![](https://img.aspxhome.com/file/UploadPic/20098/19/01-12s.png)
Python数据分析之双色球统计两个红和蓝球哪组合比例高的方法
2021-05-14 01:15:57
![](https://img.aspxhome.com/file/2023/7/105267_0s.jpg)
Yii2框架实现登陆添加验证码功能示例
2023-11-21 11:36:32
Python实现好友全头像的拼接实例(推荐)
2021-08-21 17:29:35
![](https://img.aspxhome.com/file/2023/1/75911_0s.jpg)
Python决策树分类算法学习
2023-01-28 17:27:05
![](https://img.aspxhome.com/file/2023/2/79492_0s.png)