powerpoint: decide to use unoconv based on the number of lines in catppt output

This commit is contained in:
Jean-Francois Dockes 2013-11-12 10:40:07 +01:00
parent a9358d2f03
commit 134153e412

View File

@ -30,8 +30,6 @@ LC_ALL=C ; export LC_ALL
progname="rclppt" progname="rclppt"
filetype=powerpoint filetype=powerpoint
RCLPPT_CATPPT=${RCLPPT_CATPPT:=yes}
#RECFILTCOMMONCODE #RECFILTCOMMONCODE
############################################################################## ##############################################################################
# !! Leave the previous line unmodified!! Code imported from the # !! Leave the previous line unmodified!! Code imported from the
@ -98,29 +96,16 @@ umask 77
# !! Leave the following line unmodified ! # !! Leave the following line unmodified !
#ENDRECFILTCOMMONCODE #ENDRECFILTCOMMONCODE
if test X$RCLPPT_CATPPT = Xyes ; then havecappt=no
checkcmds catppt iscmd cappt && havecappt=yes
haveunoconv=no
iscmd unoconv && haveunoconv=yes
iscmd pdftotext || haveunoconv=no
# output the result if test X$havecatppt = Xno -a X$haveunoconv = Xno ; then
echo '<html><head>' # checkcmds will exit with the appropriate salutations
#echo '<title>' "$title" '</title>' checkcmds catppt unoconv pdftotext
echo '<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">' fi
echo '</head><body>'
echo '<pre>'
catppt -d utf-8 "$infile" | \
sed -e 's/</&lt;/g' -e 's/&/&amp;/g'
echo '</pre>'
echo '</body></html>'
# exit normally
exit 0
else
# Using unoconv
checkcmds unoconv pdftotext
# This needs a temp dir because we first output pdf (outputting html # This needs a temp dir because we first output pdf (outputting html
# would produce one file per page), and pdftotext can't read from # would produce one file per page), and pdftotext can't read from
@ -137,6 +122,7 @@ else
mkdir $tmpdir || exit 1 mkdir $tmpdir || exit 1
mkdir $tmpdir/rclppttmp || exit 1 mkdir $tmpdir/rclppttmp || exit 1
unopdf=$tmpdir/rclppttmp/output.pdf unopdf=$tmpdir/rclppttmp/output.pdf
cattxt=$tmpdir/rclppttmp/output.txt
cleanup() cleanup()
{ {
# Note that we're using a constant part (rclkwdtmp), that hopefully # Note that we're using a constant part (rclkwdtmp), that hopefully
@ -144,8 +130,34 @@ else
rm -rf $tmpdir/rclppttmp rm -rf $tmpdir/rclppttmp
rmdir $tmpdir rmdir $tmpdir
} }
trap cleanup EXIT HUP QUIT INT TERM trap cleanup EXIT HUP QUIT INT TERM
# Try catppt. If the output looks too small and unoconv is available, use this
# instead. unoconv is very slow but it handles newer files that catppt will
# not convert.
#
# I'm not sure of the right test for detecting catppt failure. On the
# sample I have, it outputs Azure\n1_Azure\n\n. I don't know if Azure
# is a good marker of failure. Anyway, it seems unlikely that a real
# ppt would have fewer than 5 lines
catppt -d utf-8 "$infile" > $cattxt
lines=`wc -l < $cattxt`
if test $lines -lt 5 -a X$haveunoconv = Xyes; then
unoconv -f pdf -o $unopdf "$infile" unoconv -f pdf -o $unopdf "$infile"
`dirname $0`/rclpdf $unopdf `dirname $0`/rclpdf $unopdf
else
# output the catppt result
echo '<html><head>'
#echo '<title>' "$title" '</title>'
echo '<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">'
echo '</head><body>'
echo '<pre>'
catppt -d utf-8 "$infile" | \
sed -e 's/</&lt;/g' -e 's/&/&amp;/g' < $cattxt
echo '</pre>'
echo '</body></html>'
fi fi