scripts

My personal collection of scripts
git clone git://src.gearsix.net/scripts
Log | Files | Refs | Atom | README | LICENSE

compress-pdf.sh (882B)


      1 #!/bin/sh
      2 # DESCRIPTION: i do this often enough to write a script but not often enough to memorize the arguments
      3 # DEPENDENCIES: ghostscript
      4 # ARGUMENTS: $1 = input file, [$2 = output file (default: compressed.pdf)]
      5 # e.g.$: compress-pdf my-pdf.pdf my-pdf-compressed.pdf
      6 
      7 if [ -z $1 ] || [ -z $2 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
      8 	echo "Usage: compress-pdf [SETTINGS] INPUT [OUTPUT]"
      9 	echo ""
     10 	echo "for SETTINGS options, see https://web.mit.edu/ghostscript/www/Ps2pdf.htm#Options"
     11 	echo "INPUT should provide the filepath of a PDF to compress"
     12 	echo "OUTPUT should provided the filepath of the compressed PDF (default: ./compressed.pdf)"
     13 	echo ""
     14 	echo "Dependencies: ghostscript"
     15 	exit
     16 fi
     17 
     18 in="$1"
     19 out="compressed.pdf"
     20 if [ -e $2 ]; then out="$2"; fi
     21 
     22 gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=$1 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=$out $in
     23