ambevar-dotfiles/.scripts/pdfcompress

26 lines
738 B
Plaintext
Raw Normal View History

#!/bin/sh
if [ $# -lt 1 ] || [ $# -gt 2 ] || [ "$1" = "-h" ]; then
cat <<EOF
Usage: ${0##*/} PDFFILE [DESTFILE]
WARNING: use this function with caution. It may drastically improve compression
of some PDF files, but in some case, the output filesize will be greater! You
2013-06-25 22:56:10 +02:00
should not use it over PDF files embedding raster graphics as well.
EOF
exit
fi
if [ ! -f "$1" ]; then
2013-06-25 22:56:10 +02:00
echo "$1 is not a valid file."
fi
INPUTFILE="$1"
if [ -z "$2" ]; then
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="${INPUTFILE%%.*}-COMPRESSED.pdf" "${INPUTFILE}"
rm -rf "${INPUTFILE}"
mv "${INPUTFILE%%.*}-COMPRESSED.pdf" "${INPUTFILE}"
else
2013-06-25 22:56:10 +02:00
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="$2" "${INPUTFILE}"
fi