tjxj commited on
Commit
21196da
·
1 Parent(s): 8f35a06
.history/app_20220620160827.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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")
.history/app_20220620160828.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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")
.history/requirements_20220619225756.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ camelot-py
2
+ pdfplumber==0.7.1
3
+ xlsxwriter
4
+ pandas
5
+ streamlit
6
+ opencv-python
7
+ ghostscript==0.7
.history/requirements_20220620160853.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ ghostscript==0.7
2
+ camelot-py
3
+ pdfplumber==0.7.1
4
+ xlsxwriter
5
+ pandas
6
+ streamlit
7
+ opencv-python
app.py CHANGED
@@ -1,9 +1,10 @@
1
  #-*- coding : utf-8-*-
2
  import pandas as pd
3
- import streamlit as st
4
  import os,base64,subprocess
5
- from subprocess import STDOUT #os process manipuation
6
  os.system("apt-get install -y ghostscript")
 
 
 
7
 
8
  @st.cache
9
  def gh():
 
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
8
 
9
  @st.cache
10
  def gh():
requirements.txt CHANGED
@@ -1,7 +1,7 @@
 
1
  camelot-py
2
  pdfplumber==0.7.1
3
  xlsxwriter
4
  pandas
5
  streamlit
6
  opencv-python
7
- ghostscript==0.7
 
1
+ ghostscript==0.7
2
  camelot-py
3
  pdfplumber==0.7.1
4
  xlsxwriter
5
  pandas
6
  streamlit
7
  opencv-python