Post

Mac Tips: Easily Compress PDFs Using Terminal

Quickly compress your PDF files on Mac using Ghostscript and a simple bash function.

Mac Tips: Easily Compress PDFs Using Terminal

If you’ve ever scanned documents using the iOS Notes app, you’ve likely noticed the resulting PDF files can be excessively large—sometimes exceeding email attachment limits (like 20 MB).

Here’s a quick and efficient solution using Ghostscript:

Install Homebrew (if not already installed)

Check out my How to Install Homebrew on macOS post for detailed instructions on how to install Homebrew.

Steps

1. Install Ghostscript via Homebrew:

1
brew install ghostscript

2. Use Ghostscript to compress your PDF:

1
gs -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -dPDFSETTINGS=/screen -dCompatibilityLevel=1.4 -sOutputFile=compressed.pdf original.pdf

This command reduces your PDF size dramatically.

3. Simplify the Command with a Bash Function:

Add this handy function to your ~/.zshrc (or ~/.bash_profile for Bash users):

1
2
3
compresspdf() {
    gs -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -dPDFSETTINGS=/${3:-"screen"} -dCompatibilityLevel=1.4 -sOutputFile="$2" "$1"
}

Now compress PDFs easily with:

1
compresspdf input.pdf output.pdf

With this simple tip, you can shrink PDFs significantly—perfect for sharing or uploading!

☕ Support My Work

If you found this post helpful and want to support more content like this, you can buy me a coffee!

Your support helps me continue creating useful articles and tips for fellow developers. Thank you! 🙏

This post is licensed under CC BY 4.0 by the author.