tjxj commited on
Commit
66c288e
·
1 Parent(s): 21196da
Files changed (2) hide show
  1. .history/app_20220620161339.py +42 -0
  2. app.py +1 -1
.history/app_20220620161339.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #-*- coding : utf-8-*-
2
+ import pandas as pd
3
+ import os,base64,subprocess
4
+ os.system("apt install ghostscript python3-tk")
5
+ import streamlit as st
6
+
7
+ from subprocess import STDOUT #os process manipuation
8
+
9
+ @st.cache
10
+ def gh():
11
+ """install ghostscript on the linux machine"""
12
+ proc = subprocess.Popen('apt-get install -y ghostscript', shell=True, stdin=None, stdout=open(os.devnull,"wb"), stderr=STDOUT, executable="/bin/bash")
13
+ proc.wait()
14
+
15
+ gh()
16
+
17
+ import camelot as cam
18
+
19
+ st.title("PDF Table Extractor")
20
+
21
+ input_pdf = st.file_uploader(label = "", type = 'pdf')
22
+
23
+ page_number = st.text_input("请填写表格所在PDF页码,eg: 3", value = 1)
24
+
25
+ if input_pdf is not None:
26
+ # byte object into a PDF file
27
+ with open("input.pdf", "wb") as f:
28
+ base64_pdf = base64.b64encode(input_pdf.read()).decode('utf-8')
29
+ f.write(base64.b64decode(base64_pdf))
30
+ f.close()
31
+
32
+ # read the pdf and parse it using stream
33
+ tables = cam.read_pdf("input.pdf", pages=page_number)
34
+ result = pd.ExcelWriter('result.xlsx', engine='xlsxwriter')
35
+ tables[0].to_excel(result,index=False)
36
+ # for i in range(0,len(tables)):
37
+ # table = tables[i].df
38
+ # sheetname = str(i)
39
+ # table.to_excel(result, sheetname,index=False)
40
+
41
+ with open('result.xlsx','rb') as f:
42
+ st.download_button('提取完成,点击下载!', f,file_name='result.xlsx',mime="application/vnd.ms-excel")
app.py CHANGED
@@ -1,7 +1,7 @@
1
  #-*- coding : utf-8-*-
2
  import pandas as pd
3
  import os,base64,subprocess
4
- os.system("apt-get install -y ghostscript")
5
  import streamlit as st
6
 
7
  from subprocess import STDOUT #os process manipuation
 
1
  #-*- coding : utf-8-*-
2
  import pandas as pd
3
  import os,base64,subprocess
4
+ os.system("apt install ghostscript python3-tk")
5
  import streamlit as st
6
 
7
  from subprocess import STDOUT #os process manipuation