On macOS install Homebrew. On linux use native packamanager.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Install the ghostscript package brew install ghostscript
or apt/tdnf/whatever install ghostscript
For ZSH edit $HOME/.zshrc
and for Bash edit $HOME/.bash_profile
and put this function at the bottom:
# Usage: pdfcompress [input pdf] [output pdf]
pdfcompress() {
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dPDFSETTINGS=/${3:-"screen"} -dCompatibilityLevel=1.4 -sOutputFile="$2" "$1"
}
Run with pdfcompress input.pdf output.pdf
in Bash or ZSH.
In my experience this will reduce the original PDF with 66-75% without any significant loss of quality.