Created
September 8, 2025 02:17
-
-
Save pgmrDohan/cf2d44cf3b0e8898a7608c442789b135 to your computer and use it in GitHub Desktop.
using '$ compress.sh --file ./main.pdf'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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