目录
安装:pip install pdfplumber -i https://pypi.tuna.tsinghua.edu.cn/simple/

提取文本内容
python
from pdfplumber import open as op
def read_pdf(pdf_path):
with op(pdf_path) as pdf:
for page in pdf.pages:
# 包含表格在内的所有文本信息
text = page.extract_text()
print(text)

提取表格内容
可将提取到的表格数据通过写表的方式插入到excel中或做其他处理
python
for table in page.extract_tables():
for row in table:
print(row)

提取图片信息
python
for img in page.images:
print(img)

文本框信息数据
python
for wds in page.extract_words(): # 文本框位置及内容
print(wds)

将对应页转为图片
resolution参数为像素值,值越大,图片越清晰
python
page.to_image(resolution=500).save(rf'{pdf_path.split(".")[0]}-{page.page_number}.png')
转CSV、JSON、字典数据
python
print(page.to_csv()) # 转csv数据
print(page.to_json(indent=4)) # 转JSON数据
print(page.to_dict()) # 转字典数据