pdf相关的python库

本文说明

最近接触pdf信息抽取,使用了几个操作pdf的python库,这里简单纪录下。

pypdf

pypdf是一个免费的、开源的纯python PDF库,能够拆分、合并、裁剪和转换PDF文件的页面。它还可以为PDF文件添加自定义数据、查看选项和密码。pypdf也可以从pdf中检索文本和元数据。

总结:主要用来修改pdf,特别是拆分和合并,使用下来很方便。

PyPDF2在3.0.1版本后不再维护了,这个项目变成 了pypdf。

安装:pip install pypdf

pdfplumber

该库可以从pdf中提取文本和表格。支持可视化调试功能。

支持文本提取的库不少,但是支持表格提取的并不算多。

提取表格的效果我试了下,勉强能用,错误不少,可能需要尝试不同的提取设置选项才能得到较好的效果。

安装方法:pip install pdfplumber

pdfservices-python-sdk

这是adobe官方pdf转换服务的sdk库,需要在adobe网站注册账号才能用。少量使用免费,大量使用收费。

我试了下它的pdf表格提取功能,效果比较惊艳,比开源库的效果要好不少。但是大量调用收费,这也是个缺点。

adobe官方有个展示pdf信息抽取的可视化页面,用于可视化展示它的api进行信息抽取的效果:https://acrobatservices.adobe.com/dc-visualizer-app/index.html

安装方法:pip install pdfservices-sdk

###PyMuPDF

这个库的功能类似pypdf和pdfplumber的集合体,既可以对pdf进行编辑,又可以提取pdf信息。但是不支持提取表格。

我没使用过这个库,但是看到h2ogpt这个项目在做文档知识抽取的时候用PyMuPDF提取文本内容,就写下来了。

比较

这里摘抄pdfplumber的github说明里的一段比较文字:

python 复制代码
pdfminer.six provides the foundation for pdfplumber. It primarily focuses on parsing PDFs, analyzing PDF layouts and object positioning, and extracting text. It does not provide tools for table extraction or visual debugging.

PyPDF2 is a pure-Python library "capable of splitting, merging, cropping, and transforming the pages of PDF files. It can also add custom data, viewing options, and passwords to PDF files." It can extract page text, but does not provide easy access to shape objects (rectangles, lines, etc.), table-extraction, or visually debugging tools.

pymupdf is substantially faster than pdfminer.six (and thus also pdfplumber) and can generate and modify PDFs, but the library requires installation of non-Python software (MuPDF). It also does not enable easy access to shape objects (rectangles, lines, etc.), and does not provide table-extraction or visual debugging tools.

camelot, tabula-py, and pdftables all focus primarily on extracting tables. In some cases, they may be better suited to the particular tables you are trying to extract.
相关推荐
小蕾Java12 分钟前
PyCharm 软件使用各种问题 ,解决教程
ide·python·pycharm
Lucky_Turtle14 分钟前
【PyCharm】设置注释风格,快速注释
python
kunge1v531 分钟前
学习爬虫第四天:多任务爬虫
爬虫·python·学习·beautifulsoup
萧鼎41 分钟前
Python schedule 库全解析:从任务调度到自动化执行的完整指南
网络·python·自动化
B站_计算机毕业设计之家2 小时前
机器学习实战项目:Python+Flask 汽车销量分析可视化系统(requests爬车主之家+可视化 源码+文档)✅
人工智能·python·机器学习·数据分析·flask·汽车·可视化
羊羊小栈2 小时前
基于「多模态大模型 + BGE向量检索增强RAG」的航空维修智能问答系统(vue+flask+AI算法)
vue.js·人工智能·python·语言模型·flask·毕业设计
星期天要睡觉2 小时前
模型部署——Flask 部署 PyTorch 模型
pytorch·python·flask
weixin_456904272 小时前
SHAP可视化代码详细讲解
python
DTS小夏2 小时前
算法社Python基础入门面试题库(新手版·含答案)
python·算法·面试
刘一哥GIS3 小时前
Windows环境搭建:PostGreSQL+PostGIS安装教程
数据库·python·arcgis·postgresql·postgis