I need to accept all revisions for a word document and convert it to html using Python. I have a code that worked for some time, but I’m now getting errors after upgrading the aspose api.
My code:
def convertWordToHTML(self, word, isDocxFormatted):
with tempfile.NamedTemporaryFile(mode='wb+') as tmp:
tmp.write(word)
tmp.seek(0)
# Upload original document to cloud storage.
extension = 'docx'
if not isDocxFormatted:
extension = 'rtf'
dest_name = uuid.uuid4().hex + '.' + extension
upload_file_request = asposewordscloud.models.requests.UploadFileRequest(file_content = tmp, path = dest_name)
response = self.words_api.upload_file(upload_file_request)
# Calls AcceptAllRevisions method for document in cloud.
request = asposewordscloud.models.requests.AcceptAllRevisionsRequest(name = dest_name)
response = self.words_api.accept_all_revisions(request)
html_file = uuid.uuid4().hex + ".html"
request_save_options_data = asposewordscloud.HtmlSaveOptionsData(save_format="html"
file_name = html_file,
pretty_format=True)
request = asposewordscloud.models.requests.SaveAsRequest(name = dest_name, save_options_data = request_save_options_data)
response = self.words_api.save_as(request)
request = asposewordscloud.models.requests.DownloadFileRequest(path = html_file)
result = self.words_api.download_file(request)
with open(result, 'r', encoding="utf-8") as fh:
html = fh.read()
return html