2013-03-03 11:19:50 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2014-01-08 21:37:21 +01:00
|
|
|
## Some JPEG options
|
|
|
|
# -sDEVICE=jpeg
|
|
|
|
# -dUseCIEColor
|
|
|
|
# -dJPEGQ=100
|
|
|
|
# -r300
|
|
|
|
# -dTextAlphaBits=4
|
|
|
|
# -dGraphicsAlphaBits=4
|
|
|
|
# -dMaxStripSize=8192
|
|
|
|
|
2014-11-12 16:15:39 +01:00
|
|
|
_usage () {
|
|
|
|
cat <<EOF
|
2013-10-23 12:29:16 +02:00
|
|
|
Usage: ${1##*/} [OPTIONS] PDFFILES
|
|
|
|
|
|
|
|
All PDF files will be compressed to a PDF file with "-compressed" appended in its name.
|
2013-03-03 11:19:50 +01:00
|
|
|
|
2013-10-23 12:29:16 +02:00
|
|
|
Options:
|
|
|
|
|
2014-01-08 21:37:21 +01:00
|
|
|
-c: Compress raster graphics at the expense of a quality loss.
|
2013-10-23 12:29:16 +02:00
|
|
|
-f: Overwrite existing files.
|
2014-01-08 21:37:21 +01:00
|
|
|
-h: Show this help.
|
2013-10-23 12:29:16 +02:00
|
|
|
-i: In-place compression.
|
2014-01-08 21:37:21 +01:00
|
|
|
-n: Do not compress raster graphics at all. Output size is usually greater.
|
|
|
|
|
|
|
|
For more details:
|
|
|
|
|
2014-02-18 09:16:19 +01:00
|
|
|
$ gs -sDEVICE=pdfwrite -o /dev/null \\
|
|
|
|
-c "currentpagedevice { exch ==only ( ) print == } forall"
|
2014-01-08 21:37:21 +01:00
|
|
|
|
|
|
|
http://partners.adobe.com/public/developer/en/acrobat/sdk/pdf/pdf_creation_apis_and_specs/DistillerParameters.pdf
|
2013-10-23 12:29:16 +02:00
|
|
|
|
2013-03-03 11:19:50 +01:00
|
|
|
EOF
|
2013-10-23 12:29:16 +02:00
|
|
|
}
|
2013-03-03 11:19:50 +01:00
|
|
|
|
2013-10-23 12:29:16 +02:00
|
|
|
OPT_INPLACE=false
|
|
|
|
OPT_OVERWRITE=false
|
2014-01-08 21:37:21 +01:00
|
|
|
OPT_COMPRESSION="-dColorConversionStrategy=/LeaveColorUnchanged -dDownsampleMonoImages=false -dDownsampleGrayImages=false -dDownsampleColorImages=false -dAutoFilterColorImages=false -dAutoFilterGrayImages=false -dColorImageFilter=/FlateEncode -dGrayImageFilter=/FlateEncode"
|
|
|
|
|
|
|
|
while getopts ":cfhin" opt; do
|
2014-11-12 16:15:39 +01:00
|
|
|
case $opt in
|
|
|
|
c)
|
|
|
|
OPT_COMPRESSION="" ;;
|
|
|
|
f)
|
|
|
|
OPT_OVERWRITE=true ;;
|
|
|
|
h)
|
|
|
|
_usage "$0"
|
|
|
|
exit 1 ;;
|
|
|
|
i)
|
|
|
|
OPT_INPLACE=true ;;
|
|
|
|
n)
|
|
|
|
OPT_COMPRESSION="-dColorConversionStrategy=/LeaveColorUnchanged -dEncodeColorImages=false -dEncodeGrayImages=false -dEncodeMonoImages=false" ;;
|
|
|
|
\?)
|
|
|
|
_usage "$0"
|
|
|
|
exit 1 ;;
|
|
|
|
esac
|
2013-10-23 12:29:16 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
shift $(($OPTIND - 1))
|
|
|
|
|
|
|
|
if [ $# -eq 0 ]; then
|
2014-11-12 16:15:39 +01:00
|
|
|
_usage "$0"
|
|
|
|
exit 1
|
2013-03-03 11:19:50 +01:00
|
|
|
fi
|
2013-10-23 12:29:16 +02:00
|
|
|
|
|
|
|
for i ; do
|
|
|
|
|
2014-11-12 16:15:39 +01:00
|
|
|
if [ ! -f "$i" ]; then
|
|
|
|
echo "$i is not a valid file."
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$i" in
|
|
|
|
*/*) ;;
|
|
|
|
*) i="./$i" ;;
|
|
|
|
esac
|
|
|
|
DIRNAME="${i%/*}"
|
|
|
|
BASENAME="${i##*/}"
|
|
|
|
EXTNAME="${BASENAME##*.}"
|
|
|
|
BASENAME="${BASENAME%.*}"
|
|
|
|
OUTPUT="$DIRNAME/$BASENAME-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
|
2013-10-23 12:29:16 +02:00
|
|
|
done
|