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)

打印结果:

相关推荐
rebekk2 分钟前
pytorch custom op的简单介绍
人工智能·pytorch·python
qq_334903156 分钟前
高性能网络协议栈
开发语言·c++·算法
chushiyunen8 分钟前
uv使用笔记(python包的管理工具)
笔记·python·uv
曲幽8 分钟前
FastAPI状态共享秘籍:别再让中间件、依赖和路由“各自为政”了!
python·fastapi·web·request·state·depends·middleware
阿贵---10 分钟前
模板编译期循环展开
开发语言·c++·算法
2601_9540236610 分钟前
Beyond the Hype: Deconstructing the 2025 High-Performance Stack for Agencies
java·开发语言·算法·seo·wordpress·gpl
风清扬【coder】11 分钟前
Anaconda 被误删后抢救手册:数据恢复 + 环境重建应急流程
python·数据恢复·anaconda·环境重建
2401_8845632413 分钟前
进阶技巧与底层原理
jvm·数据库·python
2401_8732046513 分钟前
使用Pandas进行数据分析:从数据清洗到可视化
jvm·数据库·python
l1t14 分钟前
DeepSeek 辅助编写python程序求解欧拉计划932题:2025数
开发语言·python·欧拉计划