-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_pdf.py
More file actions
46 lines (31 loc) · 1011 Bytes
/
parse_pdf.py
File metadata and controls
46 lines (31 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import textract # pip3 install textract
from os import listdir
from os.path import isfile, join
def main():
print('\nFor copy-paste convenience, \ndouble-click and copy:\n')
show_PDFs_in_current_directory()
file_name = file_prompt()
text = textract.process(file_name)
pages = split_into_PDF_pages(text)
print(f'\nPages: {len(pages)}\n')
def show_PDFs_in_current_directory():
pdf_file_names = [f for f in listdir('.') if isfile(
join('.', f)) and f.endswith('.pdf')]
print('\n'.join(pdf_file_names))
def file_prompt():
file_name = ''
try:
# Python 3:
file_name = input('\nPDF file name?\n')
except:
# Python 2:
file_name = raw_input('\nPDF file name?\n')
return file_name
def split_into_PDF_pages(text):
new_page_character = r'\x0c'
pages = str(text).split(new_page_character)
return pages
def show_stats(text):
pages = split_into_PDF_pages(text)
print(f'\nPages: {len(pages)}\n')
main()