91 lines
2.1 KiB
Bash
Executable File
91 lines
2.1 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
## Some JPEG options
|
|
# -sDEVICE=jpeg
|
|
# -dUseCIEColor
|
|
# -dJPEGQ=100
|
|
# -r300
|
|
# -dTextAlphaBits=4
|
|
# -dGraphicsAlphaBits=4
|
|
# -dMaxStripSize=8192
|
|
|
|
_printhelp ()
|
|
{
|
|
cat <<EOF
|
|
Usage: ${1##*/} [OPTIONS] PDFFILES
|
|
|
|
All PDF files will be compressed to a PDF file with "-compressed" appended in its name.
|
|
|
|
Options:
|
|
|
|
-c: Compress raster graphics at the expense of a quality loss.
|
|
-f: Overwrite existing files.
|
|
-h: Show this help.
|
|
-i: In-place compression.
|
|
-n: Do not compress raster graphics at all. Output size is usually greater.
|
|
|
|
For more details:
|
|
|
|
$ gs -sDEVICE=pdfwrite -o /dev/null \
|
|
-c "currentpagedevice { exch ==only ( ) print == } forall"
|
|
|
|
http://partners.adobe.com/public/developer/en/acrobat/sdk/pdf/pdf_creation_apis_and_specs/DistillerParameters.pdf
|
|
|
|
EOF
|
|
}
|
|
|
|
OPT_INPLACE=false
|
|
OPT_OVERWRITE=false
|
|
OPT_COMPRESSION="-dColorConversionStrategy=/LeaveColorUnchanged -dDownsampleMonoImages=false -dDownsampleGrayImages=false -dDownsampleColorImages=false -dAutoFilterColorImages=false -dAutoFilterGrayImages=false -dColorImageFilter=/FlateEncode -dGrayImageFilter=/FlateEncode"
|
|
|
|
while getopts ":cfhin" opt; do
|
|
case $opt in
|
|
c)
|
|
OPT_COMPRESSION="" ;;
|
|
f)
|
|
OPT_OVERWRITE=true ;;
|
|
h)
|
|
_printhelp "$0"
|
|
exit 1 ;;
|
|
i)
|
|
OPT_INPLACE=true ;;
|
|
n)
|
|
OPT_COMPRESSION="-dColorConversionStrategy=/LeaveColorUnchanged -dEncodeColorImages=false -dEncodeGrayImages=false -dEncodeMonoImages=false" ;;
|
|
?)
|
|
_printhelp "$0"
|
|
exit 1 ;;
|
|
:)
|
|
_printhelp "$0"
|
|
exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
shift $(($OPTIND - 1))
|
|
|
|
if [ $# -eq 0 ]; then
|
|
_printhelp "$0"
|
|
exit 1
|
|
fi
|
|
|
|
for i ; do
|
|
|
|
if [ ! -f "$i" ]; then
|
|
echo "$i is not a valid file."
|
|
continue
|
|
fi
|
|
|
|
OUTPUT="${i%.*}-compressed.pdf"
|
|
if [ -e "$OUTPUT" ] && ! $OPT_OVERWRITE; then
|
|
echo "$OUTPUT alredy present. Skipping."
|
|
continue
|
|
fi
|
|
|
|
echo "$i"
|
|
|
|
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite $OPT_COMPRESSION -sOutputFile="$OUTPUT" "$i"
|
|
if $OPT_INPLACE; then
|
|
rm -f "$i"
|
|
mv "$OUTPUT" "$i"
|
|
fi
|
|
done
|