#!/bin/bash

# Larry's handy-dandy pdf distiller --- beats Adobe Distiller ;)

# adjust resolution to your preference 
IMAGERES=600

usage ()
{
    echo "Usage: $0 infile outfile"
    exit 1
}

if [ "$1" == "" ] ; then usage ; fi
if [ "$2" == "" ] ; then usage ; fi
    
INFILE=$1
OUTFILE=$2

/usr/bin/gs -sDEVICE=pdfwrite -dDownsampleColorImages=true -dDownsampleGrayImages=true -dDownsampleMonoImages=true -dColorImageResolution=$IMAGERES -dGrayImageResolution=$IMAGERES -dMonoImageResolution=$IMAGERES -dEmbedAllFonts=true -dSubsetFonts=true -dConvertCMYKImagesToRGB=true -dCompressFonts=true -dDetectDuplicateImages=true -dNOPAUSE -dBATCH -dQUIET -sOutputFile=$OUTFILE $INFILE
