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)

打印结果:

相关推荐
XiaoLeisj1 小时前
Android Kotlin 全链路系统化指南:从基础语法、类型系统与面向对象,到函数式编程、集合操作、协程并发与 Flow 响应式数据流实战
android·开发语言·kotlin·协程
dapeng28702 小时前
分布式系统容错设计
开发语言·c++·算法
2501_945423542 小时前
用Matplotlib绘制专业图表:从基础到高级
jvm·数据库·python
2301_793804692 小时前
使用Python处理计算机图形学(PIL/Pillow)
jvm·数据库·python
qq_417695052 小时前
代码热修复技术
开发语言·c++·算法
badhope7 小时前
Mobile-Skills:移动端技能可视化的创新实践
开发语言·人工智能·git·智能手机·github
码云数智-园园8 小时前
微服务架构下的分布式事务:在一致性与可用性之间寻找平衡
开发语言
吴佳浩8 小时前
GPU 编号进阶:CUDA\_VISIBLE\_DEVICES、多进程与容器化陷阱
人工智能·pytorch·python
C++ 老炮儿的技术栈8 小时前
volatile使用场景
linux·服务器·c语言·开发语言·c++
hz_zhangrl8 小时前
CCF-GESP 等级考试 2026年3月认证C++一级真题解析
开发语言·c++·gesp·gesp2026年3月·gespc++一级