-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompress_pdf
More file actions
executable file
·34 lines (28 loc) · 812 Bytes
/
compress_pdf
File metadata and controls
executable file
·34 lines (28 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
# Check if a file path was passed
if [ -z "$1" ]; then
echo "Usage: $0 <path-to-pdf-file>"
exit 1
fi
input="$1"
# Check if file exists
if [ ! -f "$input" ]; then
echo "Error: File '$input' not found!"
exit 1
fi
# Extract filename without extension and directory
dir=$(dirname "$input")
filename=$(basename "$input" .pdf)
output="${dir}/${filename}_compressed.pdf"
# Run Ghostscript to compress the PDF
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/screen \
-dDownsampleColorImages=true \
-dColorImageResolution=150 \
-dDownsampleGrayImages=true \
-dGrayImageResolution=150 \
-dDownsampleMonoImages=true \
-dMonoImageResolution=150 \
-dNOPAUSE -dQUIET -dBATCH \
-sOutputFile="$output" "$input"
echo "Compressed file saved as: $output"