Python 3 AbiWord Library Script to Convert Word Documents & PDF Documents to HTML Files in Linux & Windows Full Project For Beginners

 

 

AbiWord Official Website

 

 

 

On Command Line Usage

 

 

abiword -t output.html resume.doc; cat output.html

 

 

 

main.py

 

 

import subprocess
import os
import uuid

def document_to_html(file_path):
    tmp = "/tmp"
    guid = str(uuid.uuid1())
    # convert the file, using a temporary file w/ a random name
    command = "abiword -t %(tmp)s/%(guid)s.html %(file_path)s; cat %(tmp)s/%(guid)s.html" % locals()
    p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, cwd=os.path.join(settings.PROJECT_DIR, "website/templates"))
    error = p.stderr.readlines()
    if error:
        raise Exception("".join(error))
    html = p.stdout.readlines()
    return "".join(html)

Leave a Reply