pdfshrink is a macOS and Linux-friendly Bash script for compressing PDF files with different quality options. It supports both interactive and flag-based workflows, optional file relocation, and safe overwrite handling.
(This was based in this old script, which was probbaly based on someone's answer on stackoverflow. This updated version includes some minor improvements, such as an install script and more options.)
- Compress PDF files using Ghostscript (
gs) - Saves compressed file side by side with original by default
- Multiple compression quality options:
- Highest-quality (prepress)
--high(-h) or--prepress(default if no arguments) - Good (printer)
--good(-g) or--printer - Medium (ebook)
--medium(-m) or--ebook - Lowest (screen)
--low(-l) or--screen
- Highest-quality (prepress)
- Interactive mode for selecting quality (
--interactive) - Optional overwrite of original file (
--override/-o) with user confirmation - Optional relocation of compressed file (
--relocate <dir>/-r <dir>)
- Bash (compatible with macOS default Bash 3.2 or Linux Bash)
- Ghostscript (
gs) installed and in$PATH - Optional: Homebrew (macOS) or apt (Linux) for automated installation
git clone https://github.com/yourname/pdfshrink.git;
cd pdfshrink;
chmod +x install.sh;
./install.sh;If you are on Mac and have brew or on linux and have apt, the installer will automatically install gs for you, if its missing.
git clone https://github.com/yourname/pdfshrink.git
cd pdfshrink
chmod +x pdfshrink.shOptionally, move it to a directory in your PATH:
mv pdfshrink.sh ~/.local/bin/pdfshrinkpdfshrink.sh [options] <file.pdf>| Option | Description |
|---|---|
| -i, --interactive | Select compression quality interactively |
| -h, --prepress, --high | Highest quality (prepress) [default] |
| -g, --printer, --good | Good quality (printer) |
| -m, --ebook, --medium | Medium quality (ebook) |
| -l, --low, --screen | Lowest quality (screen) |
| -o, --override | Replace the original file after compression (asks confirmation) |
| -r, --relocate | Move the compressed file to the specified directory |
| --help | Show help message |
# Compress with default prepress quality
pdfshrink.sh file.pdf
# Interactive quality selection
pdfshrink.sh -i file.pdf
# Medium quality, override original file
pdfshrink.sh -m -o file.pdf
# Low quality and relocate compressed file
pdfshrink.sh -l -r ~/Desktop/Compressed file.pdfGNU GPL