代碼量極少,但是比pdfminer實現的功能強大。(主觀感受,不代表他人)
# -*- coding: utf-8 # File : pdfpdfplumberRead.py # Author : baoshan import pdfplumber path = "D:\\nianjian.md.pdf" path = "D:\\0.shenma\\01.xx資料\\01.數據資料\\02.xx年鑒數據\\2018年年鑒(實則2017年全年數據).pdf" pdf = pdfplumber.open(path) for page in pdf.pages: print(page.extract_text()) print('-'*100) # for table in page.extract_table(): # for row in table: # print(row) # print('-'*10) pdf.close()
轉換較好的表格如下
1-6 主要城市平均氣溫 (2017年) 單位:攝氏度/日 縣市區 東昌府 臨 清 陽 谷 莘 縣 茌 平 東 阿 冠 縣 高 唐 月 份 一 月 -0.1 -0.5 0.6 0.6 -0.6 -0.4 -0.6 二 月 3.1 2.9 4.1 3.8 2.7 3.7 3.2 2.8 三 月 8.3 8.4 8.9 8.9 7.9 8.3 8.4 8.3 四 月 15.7 15.6 16.3 16.3 15.1 15.9 15.7 15.7 五 月 22.2 22.1 22.9 22.6 21.9 22.7 21.9 22.5 六 月 24.7 24.9 25.7 25.5 24.7 25.5 24.6 25 七 月 27.6 27.4 28 27.8 27.6 28 27.5 27.6 八 月 26.4 25.8 26.5 26.5 25.9 26.5 26.1 26 九 月 22.6 22.2 23.1 23 21.9 22.7 22.2 22.3 十 月 13.9 13.7 14.5 14.3 13.7 14.2 13.3 13.8 十一月 7.5 6.7 8 7.9 6.8 7.7 6.4 6.7 十二月 0.7 0.1 1.3 1.1 0.2 1 -0.2 0.4 全 年 14.4 14.1 15.0 14.9 14.0 14.7 14.1 14.2
參考:https://www.cnblogs.com/gl1573/p/10064438.html
采用pdfplumber,部分表格的轉換格式相當可以,賊溜。。。
謝謝!