Python办公自动化教程(001):PDF内容提取

1、Pdfplumber介绍

pdfplumber的github地址:

http 复制代码
https://github.com/jsvine/pdfplumber/
  • 【介绍】:pdfplumber 是一个用于处理 PDF 文件的 Python 第三方库,它提供了一种方便的方式来提取 PDF 文件中的文本、表格和其他信息。
  • 【功能】:pdfplumber 主要用于解析和提取 PDF 文件中的文本、表格、图像等信息。
    适用版本:支持 Python 3.6 及以上版本。
  • 【特点】:简单易用、准确性高、多平台支持(包括 Windows、Mac 和 Linux)、功能强大。
  • 【安装】:pip install pdfplumber

2、内容提取

【1】读取page对象

代码:

python 复制代码
import pdfplumber

with pdfplumber.open('./file/test.pdf') as read_pdf:
    # 读取page对象
    print(read_pdf.pages)

输出结果:

【2】打印完整内容

代码:

python 复制代码
import pdfplumber

with pdfplumber.open('./file/test.pdf') as read_pdf:
    # 读取page对象
    pages = read_pdf.pages
    for page in range(len(pages)):
        text = read_pdf.pages[page].extract_text()
        print(f'--------------第{page + 1}页内容---------------')
        print(text)

打印结果:

相关推荐
Y1rong4 小时前
C++ QT之记事本
开发语言·qt
吴佳浩6 小时前
大模型量化部署终极指南:让700亿参数的AI跑进你的显卡
人工智能·python·gpu
diegoXie7 小时前
Python / R 向量顺序分割与跨步分割
开发语言·python·r语言
程序员小白条7 小时前
0经验如何找实习?
java·开发语言·数据结构·数据库·链表
七牛云行业应用7 小时前
解决OSError: No space left... 给DeepSeek Agent装上无限云硬盘
python·架构设计·七牛云·deepseek·agent开发
liulilittle7 小时前
C++ 浮点数封装。
linux·服务器·开发语言·前端·网络·数据库·c++
BoBoZz198 小时前
CutWithScalars根据标量利用vtkContourFilter得到等值线
python·vtk·图形渲染·图形处理
失散138 小时前
Python——1 概述
开发语言·python
萧鼎8 小时前
Python 图像哈希库 imagehash——从原理到实践
开发语言·python·哈希算法
qq_251533598 小时前
使用 Python 提取 MAC 地址
网络·python·macos