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
|
|
|
|
|
2013-10-23 12:29:16 +02:00
|
|
|
_printhelp ()
|
|
|
|
{
|
2013-03-03 11:19:50 +01:00
|
|
|
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
|
2013-10-23 12:29:16 +02:00
|
|
|
case $opt in
|
2014-01-08 21:37:21 +01:00
|
|
|
c)
|
|
|
|
OPT_COMPRESSION="" ;;
|
|
|
|
f)
|
|
|
|
OPT_OVERWRITE=true ;;
|
2013-10-23 12:29:16 +02:00
|
|
|
h)
|
|
|
|
_printhelp "$0"
|
|
|
|
exit 1 ;;
|
|
|
|
i)
|
|
|
|
OPT_INPLACE=true ;;
|
2014-01-08 21:37:21 +01:00
|
|
|
n)
|
|
|
|
OPT_COMPRESSION="-dColorConversionStrategy=/LeaveColorUnchanged -dEncodeColorImages=false -dEncodeGrayImages=false -dEncodeMonoImages=false" ;;
|
2013-10-23 12:29:16 +02:00
|
|
|
?)
|
|
|
|
_printhelp "$0"
|
|
|
|
exit 1 ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
shift $(($OPTIND - 1))
|
|
|
|
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
_printhelp "$0"
|
|
|
|
exit 1
|
2013-03-03 11:19:50 +01:00
|
|
|
fi
|
2013-10-23 12:29:16 +02:00
|
|
|
|
|
|
|
for i ; do
|
|
|
|
|
|
|
|
if [ ! -f "$i" ]; then
|
|
|
|
echo "$i is not a valid file."
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2014-08-19 11:06:03 +02:00
|
|
|
case "$i" in
|
|
|
|
*/*) ;;
|
|
|
|
*) i="./$i" ;;
|
|
|
|
esac
|
|
|
|
DIRNAME="${i%/*}"
|
|
|
|
BASENAME="${i##*/}"
|
|
|
|
EXTNAME="${BASENAME##*.}"
|
|
|
|
BASENAME="${BASENAME%.*}"
|
|
|
|
OUTPUT="$DIRNAME/$BASENAME-compressed.pdf"
|
2013-10-23 12:29:16 +02:00
|
|
|
if [ -e "$OUTPUT" ] && ! $OPT_OVERWRITE; then
|
|
|
|
echo "$OUTPUT alredy present. Skipping."
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "$i"
|
2014-01-08 21:37:21 +01:00
|
|
|
|
|
|
|
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite $OPT_COMPRESSION -sOutputFile="$OUTPUT" "$i"
|
2013-10-23 12:29:16 +02:00
|
|
|
if $OPT_INPLACE; then
|
|
|
|
rm -f "$i"
|
|
|
|
mv "$OUTPUT" "$i"
|
|
|
|
fi
|
|
|
|
done
|