CarolineDelva commited on
Commit
7a00a43
·
verified ·
1 Parent(s): 22cfe68

Create fileconverter.py

Browse files
Files changed (1) hide show
  1. fileconverter.py +16 -0
fileconverter.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import docx2txt
2
+ import PyPDF2
3
+
4
+ def convert_docx_file_to_txt_file(docx_path):
5
+ text = docx2txt.process(docx_path)
6
+ return text
7
+
8
+
9
+ def convert_pdf_file_to_txt_file(pdf_path):
10
+ with open(pdf_path, 'rb') as pdf_file:
11
+ pdf_reader = PyPDF2.PdfReader(pdf_file)
12
+ text = ""
13
+ for page_num in range(len(pdf_reader.pages)):
14
+ page = pdf_reader.pages[page_num]
15
+ text += page.extract_text()
16
+ return text