I have used antiword (http://www.antiword.org) in a site I made. The
visitors can view a document in text or pdf format. The results are
surprisingly good.
Here's the code I used in that site:
if {$type_srcfile == "application/msword"} {
if {$desttype == "text/plain"} {
set tmp_destfile "$tmp_filename.txt"
exec $appdir/antiword -m /usr/local/lib/antiword/8859-1.txt
-t $srcfile >$tmp_destfile
#ns_returnfile $conn 200 "text/plain" $tmp_destfile
ns_respond -status 200 -type "text/plain" -file $tmp_destfile
ns_unlink $tmp_destfile
} elseif {$desttype == "application/pdf"} {
set tmp_tmp "$tmp_filename.ps"
set tmp_destfile "$tmp_filename.pdf"
exec "$appdir/antiword" -m
/usr/local/lib/antiword/8859-1.txt -p a4 $srcfile ">$tmp_tmp"
exec gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite
-sOutputFile=$tmp_destfile -c save pop -f
#ns_returnfile $conn 200 "application/pdf" $tmp_destfile
ns_respond -status 200 -type "application/pdf" -file
$tmp_destfile
ns_unlink $tmp_tmp
ns_unlink $tmp_destfile
} else {
ns_log Notice "Sessie: $si Opgevraagd: $srcfile Formaat:
$desttype"
ns_returnnotfound
} if {$type_srcfile == "application/msword"} {
if {$desttype == "text/plain"} {
set tmp_destfile "$tmp_filename.txt"
exec $appdir/antiword -m /usr/local/lib/antiword/8859-1.txt
-t $srcfile >$tmp_destfile
#ns_returnfile $conn 200 "text/plain" $tmp_destfile
ns_respond -status 200 -type "text/plain" -file $tmp_destfile
ns_unlink $tmp_destfile
} elseif {$desttype == "application/pdf"} {
set tmp_tmp "$tmp_filename.ps"
set tmp_destfile "$tmp_filename.pdf"
exec "$appdir/antiword" -m /usr/local/lib/antiword/8859-1.txt
-p a4 $srcfile ">$tmp_tmp"
exec gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite
-sOutputFile=$tmp_destfile -c save pop -f
#ns_returnfile $conn 200 "application/pdf" $tmp_destfile
ns_respond -status 200 -type "application/pdf" -file
$tmp_destfile
ns_unlink $tmp_tmp
ns_unlink $tmp_destfile
} else {
ns_log Notice "Sessie: $si Opgevraagd: $srcfile Formaat:
$desttype"
ns_returnnotfound
}