Arcanelab Blog
text

Compressing PDFs on Macs Let’s say you have a pdf file with large embedded images in…

Compressing PDFs on Macs

Let’s say you have a pdf file with large embedded images in it and you’d like to reduce the filesize a bit, here’s how to do it using the command line.

  1. Install ghostscript via Homebrew:

brew install gs

  1. Create a shell script, let’s call it pdf2smol:
#!/bin/bash

if [ -z "$1" ]; then
    echo "Usage: pdf2smol input.pdf [output.pdf] [resolution (default: 150)]"
    exit
fi

if [ -z "$2" ]; then
    output="output.pdf"
else
    output=$2
fi

if [ -z "$3" ]; then
    resolution=150
else
    resolution=$3
fi

set -x

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook \
-dNOPAUSE -dBATCH -dColorImageResolution=$resolution \
-sOutputFile="$output" "$1"