Skip to content

Instantly share code, notes, and snippets.

@JosiasAurel
Last active December 28, 2019 13:31
Show Gist options
  • Save JosiasAurel/d1fa717f5faad9f8486623e94f63c2df to your computer and use it in GitHub Desktop.
Save JosiasAurel/d1fa717f5faad9f8486623e94f63c2df to your computer and use it in GitHub Desktop.
import mammoth
import pdftables_api
def help(): # definig a function to print help to the users
print("The following are the possible commands in this program : ")
print("Enter word_to_html to convert your word file to an html file")
print("Enter pdf_to_html to convert your pdf file to html")
print("Thanks for using this file converter")
print("Enter help for help")
choice = input("Enter the operation you want to carry :")
if choice == "word_to_html" :
path_to_file = input("_path_to_file.docx :")
f = open(path_to_file, 'rb')
b = open('converted.html', 'wb')
document = mammoth.convert_to_html(f)
b.write(document.value.encode('utf8'))
print("Your file has been converted succesfully and is in the home folder of the program. Thanks for using")
f.close()
b.close()
elif choice == "pdf_to_html" :
path_to_file = input("Enter the path to the file :")
c = pdftables_api.Client('iop40z54d71j', timeout=(60, 3600)) #the first argument here is your API key. I've used mine in this case but
# makesure you use your own. You can obtain one after registring at pdftables
c.html(path_to_file, 'converted_file.html')
elif choice == "help":
help()
else:
print("UNKNOWN COMMAND")
'''
Instructions are found using the help command.
This instructions are for those to install the file in their pc.
INSTRUCTIONS :
Download the file in zip format using the download button above this gist or copy paste in your favorite editor( making syre it has python installed)
Just run the program and your ok
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment