通过Python的pdfplumber库将pdf转为图片

前言

大家好,我是空空star,本篇给大家分享一下《通过Python的pdfplumber库将pdf转为图片》

一、pdfplumber库是什么?

pdfplumber是一个用于从PDF文档中提取文本和表格数据的Python库。它可以帮助用户轻松地从PDF文件中提取有用的信息,例如表格、文本、元数据等。pdfplumber库的特点包括:简单易用、速度快、支持多种PDF文件格式、支持从多个页面中提取数据等。pdfplumber库还提供了一些方便的方法来处理提取的数据,例如排序、过滤和格式化等。它是一个非常有用的工具,特别是在需要从大量PDF文件中提取数据时。

二、安装pdfplumber库

pip install pdfplumber

三、查看pdfplumber库版本

pip show pdfplumber

Name: pdfplumber
Version: 0.9.0
Summary: Plumb a PDF for detailed information about each char, rectangle, and line.
Home-page: https://github.com/jsvine/pdfplumber
Author: Jeremy Singer-Vine
Author-email: [email protected]
License:
Requires: pdfminer.six, Pillow, Wand
Required-by:

四、pdf素材

五、将pdf转为图片

1.引入库

import pdfplumber

2.定义pdf路径

local = '/Users/kkstar/Downloads/'

3.打开PDF文件

with pdfplumber.open(local+'demo.pdf') as pdf:

4.遍历每一页

    for i, page in enumerate(pdf.pages):

5.将PDF页面转换为Image对象

        img = page.to_image()

6.将Image对象保存为图片文件

        img.save(local+f"page_{
      
      i+1}.png")

7.效果

总结

猜你喜欢

转载自blog.csdn.net/weixin_38093452/article/details/130889268