TIL How to Batch Compress PDF Files Using Ghostscript
Nick Ciolpan

Nick Ciolpan @nickciolpan

About: I have extensive experience as a full stack developer, managing clients and building state of the art platforms.

Joined:
Jan 16, 2018

TIL How to Batch Compress PDF Files Using Ghostscript

Publish Date: Oct 6 '24
0 1
brew install ghostscript
Enter fullscreen mode Exit fullscreen mode
#!/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
Enter fullscreen mode Exit fullscreen mode
./compress_pdfs.sh /path/to/input /path/to/output /quality_setting
Enter fullscreen mode Exit fullscreen mode

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

Comments 1 total

  • saicharan
    saicharanOct 13, 2024

    Hey compressing the pdf so check this website of my friend iformat.io techniques (iformat.io/)

    Dont know what technique was implemented in this website but it is fast and responsive too!

    iformat.io/pdf-compressor this is for compressing in iformat.io once check it definitely you are gonna love it

Add comment