#!/bin/bash # # Syntax: pdf_compress_gs [-h] pdf_files # # Purpose: Use gs to "compress" a pdf file (by replacing hi-resolution # images by lower resolution ones). # Output is stored in the file pdf_file_compressed.pdf # The -h flag shows the help info for this command. # Created: Jan 10, 2011 by Bart De Schutter # Last revised: # # See http://www.deschutter.info/util/scripts.html for the latest version of # this script. # Status: public # Category: pdf # # Process options # while getopts :h option do case "$option" in h) sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1;; \?) echo >&2 echo >&2 "Unknown option: $OPTARG" echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1;; esac done shift $(($OPTIND-1)) if [ $# -eq 0 ]; then echo >&2 echo >&2 "ERROR: ${0##*/} requires at least 1 input argument." echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1 fi for fil in "$@" do basename=${fil%.pdf} gs -q -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \ -dCompatibilityLevel=1.4 \ -dEmbedAllFonts=true -dSubsetFonts=true -dMaxSubsetPct=100 \ -sOutputFile="${basename}_compressed.pdf" \ "${basename}.pdf" if [ $? -ne 0 ]; then echo >&2 echo >&2 "ERROR processing ${basename}.pdf" echo >&2 exit 1 else echo "Written ${basename}_compressed.pdf" fi done # Extra option: -sPAPERSIZE=a4 # -dPDFSETTINGS=/prepress ### -dAutoFilterColorImages=false -dAutoFilterGrayImages=false \ ### -dColorImageFilter=/FlateEncode -dGrayImageFilter=/FlateEncode \ ### -dAutoFilterMonoImages=false -dMonoImageFilter=/CCITTFaxEncode \