ambevar-dotfiles/.scripts/pdfcompress

27 lines
766 B
Bash
Executable File

#!/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
should not use it over PDF files embedding pictures as well.
EOF
exit
fi
if [ ! -f "$1" ]; then
echo "$1 is not a valid PDF 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
OUTPUTFILE="$2"
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="${OUTPUTFILE}" "${INPUTFILE}"
fi