Skip to content

Commit a0a27fa

Browse files
feat(aliases): add compresspdf function using ghostscript
1 parent 29489a5 commit a0a27fa

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

.aliases

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,39 @@ export do='--dry-run=client -o yaml'
137137
export now='--force --grace-period=0'
138138

139139

140+
# ------------------------------------------------------------------------------
141+
# | PDF Utilities |
142+
# ------------------------------------------------------------------------------
143+
144+
compresspdf() {
145+
if [ $# -lt 2 ]; then
146+
echo "Usage: compresspdf INPUT.pdf OUTPUT.pdf [dpi]"
147+
echo "Default dpi = 200 (good for scanned docs / visa uploads)"
148+
return 1
149+
fi
150+
151+
local input="$1"
152+
local output="$2"
153+
local dpi="${3:-200}" # third arg optional, default 200
154+
155+
command gs \
156+
-sDEVICE=pdfwrite \
157+
-dNOPAUSE -dQUIET -dBATCH \
158+
-dCompatibilityLevel=1.6 \
159+
-dDetectDuplicateImages=true \
160+
-dDownsampleColorImages=true \
161+
-dColorImageDownsampleType=/Average \
162+
-dColorImageResolution="$dpi" \
163+
-dDownsampleGrayImages=true \
164+
-dGrayImageDownsampleType=/Average \
165+
-dGrayImageResolution="$dpi" \
166+
-dDownsampleMonoImages=true \
167+
-dMonoImageDownsampleType=/Average \
168+
-dMonoImageResolution=300 \
169+
-sOutputFile="$output" \
170+
"$input"
171+
}
172+
140173
# ------------------------------------------------------------------------------
141174
# | Other |
142175
# ------------------------------------------------------------------------------

0 commit comments

Comments
 (0)