-
-
Save ilosamart/38e87064fba1c98b653b21ee3f865a7e to your computer and use it in GitHub Desktop.
Optimize PDF files with Ghostscript.
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
#!/usr/bin/env bash | |
# pdfoptim.sh | |
# | |
# Optimize a PDF with Ghostscript | |
# | |
# Usage | |
# ----- | |
# | |
# bash pdfoptim.sh input.pdf output.pdf | |
# | |
# For example, a PDF file can be reduced from 136.8 MB to 41.2 MB without losing details. | |
if [[ "$#" -ne 2 ]]; then | |
echo "usage: $0 in.pdf out.pdf" | |
exit 1 | |
fi | |
dpi=300 | |
downsample=0.8 | |
in_file="$1" | |
out_file="$2" | |
gs \ | |
-o"${out_file}" \ | |
-sDEVICE=pdfwrite \ | |
-dDownsampleColorImages=true \ | |
-dDownsampleGrayImages=true \ | |
-dDownsampleMonoImages=true \ | |
-dColorImageResolution=${dpi} \ | |
-dGrayImageResolution=${dpi} \ | |
-dMonoImageResolution=${dpi} \ | |
-dColorImageDownsampleThreshold=${downsample} \ | |
-dGrayImageDownsampleThreshold=${downsample} \ | |
-dMonoImageDownsampleThreshold=${downsample} \ | |
"${in_file}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment