ambevar-dotfiles/.scripts/pdfcompress

26 lines
738 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 raster graphics as well.
EOF
exit
fi
if [ ! -f "$1" ]; then
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
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="$2" "${INPUTFILE}"
fi