Spaces:
Build error

TextScout2 / fileconverter.py
CarolineDelva's picture
Create fileconverter.py
7a00a43 verified
Raw History Blame Contribute Delete
447 Bytes
import docx2txt
import PyPDF2
def convert_docx_file_to_txt_file(docx_path):
text = docx2txt.process(docx_path)
return text
def convert_pdf_file_to_txt_file(pdf_path):
with open(pdf_path, 'rb') as pdf_file:
pdf_reader = PyPDF2.PdfReader(pdf_file)
text = ""
for page_num in range(len(pdf_reader.pages)):
page = pdf_reader.pages[page_num]
text += page.extract_text()
return text