赞
踩
在python中有许多开源的库可以处理Pdf文档,最常用的Pypdf2库可以读取文档,合并,分割pdf文档,但是也有局限性:
无法提取文档中的文字
提取PDF文字需要使用另外的库,如pdfplumbe
提取PDF中的图片需要使用fitz库
pdfplumbe使用可以用来解析PDF文件,获取其文本内容、标题、表格等的开源工具;
开源代码地址:https://github.com/jsvine/pdfplumber
安装pdfplumbe:
pip install pdfplumbe
引入:
import pdfplumbe
简单使用代码示例:
filepath = 'H:/test_w.pdf' def extract_text_info(filepath): """ 提取PDF中的文字 @param filepath:文件路径 @return: """ with pdfplumber.open(filepath) as pdf: # 获取第2页数据 page = pdf.pages[3] print(page.extract_text()) #提取文字 table = page.extract_tables() #提取表格 print(table) for row in table:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。