def convert_to_html(uid,imagedate,f_address, lang): import os import subprocess import stat import time import pdftotree import mammoth file_name = uid+'/report.docx' #b_cmd = 'libreffice --convert-to pdf ' + file_name f_address = f_address.replace(" ","_") f_address = f_address.replace(",","_") doc_name=uid+'/report.html' if os.path.exists(doc_name): os.remove(doc_name) template_html = '''
''' with open(file_name, "rb") as docx_file: result = mammoth.convert_to_html(docx_file) html = result.value # The generated HTML messages = result.messages # Any messages, such as warnings during conversion Html_file= open(doc_name,"w") Html_file.write(template_html) Html_file.write(html) Html_file.write('
') Html_file.close()