TIL How to Batch Compress PDF Files Using Ghostscript
Nick Ciolpan
Posted on October 6, 2024
brew install ghostscript
#!/bin/bash
[ $# -lt 3 ] && { echo "Usage: $0 /input_dir /output_dir /quality"; exit 1; }
input_dir="$1"; output_dir="$2"; quality="$3"
mkdir -p "$output_dir"
for file in "$input_dir"/*.pdf; do
base=$(basename "$file" .pdf)
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS="$quality" -dNOPAUSE -dQUIET -dBATCH -sOutputFile="$output_dir/${base}_compressed.pdf" "$file"
done
./compress_pdfs.sh /path/to/input /path/to/output /quality_setting
Quality options: /screen, /ebook, /printer, /prepress.
Say goodbye to online pdf converters.
Originally posted on: https://graffino.com/til/til-how-to-batch-compress-pdf-files-using-ghostscript
💖 💪 🙅 🚩
Nick Ciolpan
Posted on October 6, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.