- Install ghostscript:
brew install ghostscript
.
- Save the following script as
compress-pdf.sh
.
#!/bin/bash
input=$1
tmp="-tmp.pdf"
output="${input/.pdf/$tmp}"
echo "Compressing..."
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=$output $input && \
echo "Shuffling some files around..." && \
rm $input && \
mv $output $input && \
echo "Done!"
- Make the script executable:
chmod +x compress-pdf.sh
.
- Run the script:
./compress-pdf.sh <filename.pdf>
.
- (Optional) Create an alias in your
.bash_profile
or .zshrc
file: alias compress-pdf='./compress-pdf.sh'
.