Skip to content

Instantly share code, notes, and snippets.

@pgmrDohan
Created September 8, 2025 02:17
Show Gist options
  • Select an option

  • Save pgmrDohan/cf2d44cf3b0e8898a7608c442789b135 to your computer and use it in GitHub Desktop.

Select an option

Save pgmrDohan/cf2d44cf3b0e8898a7608c442789b135 to your computer and use it in GitHub Desktop.
using '$ compress.sh --file ./main.pdf'
#!/bin/bash
# Default values
FILE=""
QUALITY="/screen"
# Parse arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--file) FILE="$2"; shift ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done
if [[ -z "$FILE" ]]; then
echo "Usage: $0 --file <input.pdf>"
exit 1
fi
if [[ ! -f "$FILE" ]]; then
echo "File not found: $FILE"
exit 1
fi
OUT_FILE="${FILE%.pdf}_compressed.pdf"
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=$QUALITY \
-dNOPAUSE -dQUIET -dBATCH -sOutputFile="$OUT_FILE" "$FILE"
echo "Compressed PDF saved as $OUT_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment