-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDocFile.py
More file actions
52 lines (43 loc) · 1.55 KB
/
DocFile.py
File metadata and controls
52 lines (43 loc) · 1.55 KB
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
47
48
49
50
import zipfile
import unicodedata
from xml.etree.ElementTree import XML
import fitz
import json
from operator import itemgetter
from itertools import groupby
class DocFile:
def __init__(self, name):
self.location = './cv_docs/' + name
self.format = self.location.split(".")[-1]
def pdf2textlines(self):
document = list()
if self.format == 'pdf':
document = fitz.open(self.location)
else:
print('Error! This file is not in PDF format')
if document:
header = "CONTACT INFORMATION"
footer = "OBJECTIVE"
dict = {}
font_dict = {}
words = []
for page in document:
display_list = page.getDisplayList()
text_page = display_list.getTextPage()
text = text_page.extractJSON()
texts = page.get_text_words()
words.append(texts)
html = text_page.extractHTML()
page_dict = json.loads(text)
for i in page_dict['blocks']:
line = []
origin = []
for j in i['lines']:
for k in j['spans']:
if len(k['text'].split()):
dict[k['text']] = k['origin']
font_dict[k['text']]=k['size']
return dict , font_dict, words
else:
print('Reading PDF file aborted.')
return None