Changes
Browse files- ExtractContentsFromFile.py +20 -13
ExtractContentsFromFile.py
CHANGED
@@ -9,17 +9,24 @@ warnings.filterwarnings('ignore')
|
|
9 |
class ExtractContentFromFile:
|
10 |
def ExtractDataFromFile(FileName,file):
|
11 |
text =''
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
return text
|
|
|
9 |
class ExtractContentFromFile:
|
10 |
def ExtractDataFromFile(FileName,file):
|
11 |
text =''
|
12 |
+
try:
|
13 |
+
#print(text)
|
14 |
+
if FileName.endswith("pdf"):
|
15 |
+
reserve_pdf_on_memory = io.BytesIO(file)
|
16 |
+
load_pdf = PyPDF2.PdfReader(reserve_pdf_on_memory)
|
17 |
+
for page in load_pdf.pages:
|
18 |
+
text += page.extract_text()
|
19 |
+
|
20 |
+
elif FileName.endswith("doc") or FileName.endswith("docx"):
|
21 |
+
text = docx2txt.process(file)
|
22 |
+
text = text.read()
|
23 |
+
|
24 |
+
else:
|
25 |
+
text = file.decode('utf-8')
|
26 |
+
except:
|
27 |
+
print("Error reading file")
|
28 |
+
finally:
|
29 |
+
# Close the resources to free up memory
|
30 |
+
del reserve_pdf_on_memory
|
31 |
+
del load_pdf
|
32 |
return text
|