Forum OpenACS Q&A: Re: Handling of Word upload & general question

Collapse
Posted by Alfred Werner on
ad_proc -public mime_type_convert::doc_to_html {
    filename
} {
    @param filename full path to file to be converted
} {
    # let's just start with inputting a Word file and outputting some xhtml
    set tmpdir [lindex [parameter::get -package_id [ad_conn subsite_id] -parameter TmpDir -default "/tmp"] 0]
    # create a temporary file to hold the converted data
    set new_filename [file tail [ns_mktemp "${tmpdir}/fileXXXXXX"]]
    # convert to HTML
    exec /usr/bin/wvHtml --targetdir=${tmpdir} ${filename} ${new_filename}
    # clean up word HTML
    set err [catch {exec sh -c "(tidy -c -i -q ${tmpdir}/${new_filename} 2> /dev/null ;/bin/true)" } msg]
    return $msg
}