前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >python pdf 转 image

python pdf 转 image

原创
作者头像
vell001
发布2018-10-29 10:11:16
发布2018-10-29 10:11:16
5K0
举报
文章被收录于专栏:AI-vellAI-vell

前言

最近项目需要pdf中提取内容,pdf是扫描版,想通过转成图片,通过图像识别区分出段落,然后进行ocr识别,得到结构化数据

所以第一步需要搞定的就是pdf转图片了

环境:Mac 10.12.6 (16G29)

正文

安装依赖

注意imagemagick,目前不支持最新的7版本,所以只能装6

代码语言:txt
复制
brew install freetype
brew install GhostScript
brew install imagemagick@6
brew link --overwrite imagemagick@6
echo 'export MAGICK_HOME=/usr/local/opt/imagemagick@6' >> ~/.bash_profile
echo 'export PATH="$MAGICK_HOME/bin:$PATH"' >> ~/.bash_profile
pip install Wand

python 脚本

代码语言:txt
复制
from wand.image import Image
# Converting first page into JPG
with Image(filename="/thumbnail.pdf[0]") as img:
     img.save(filename="/temp.jpg")

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 前言
  • 正文
    • 安装依赖
    • python 脚本
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档