- import pdfplumber
- with pdfplumber.open('test.pdf') as PDF:
- #page_count = len(PDF.pages())
- p0 = PDF.pages[0]
- # 获取文本, 直接得到字符串, 包括了换行符 [与 PDF 上的换行位置一致, 而不是实际的 "段落"]
- #print(p0.extract_text())
- # 获取本页全部表格, 也可以使用 extract_table() 获得单个表格
- for table in p0.extract_tables():
- #得到的 table 是嵌套 list 类型, 转化成 DataFrame 更加方便查看和分析
- for line in table:
- print(line)
- #安装 ImageMagick, 地址在下面
- #http://docs.wand-py.org/en/latest/guide/install.html#install-imagemagick-on-windows
- #https://blog.csdn.net/blmoistawinde/article/details/82051915
来源: http://www.bubuko.com/infodetail-2851022.html