Skip to content

Instantly share code, notes, and snippets.

@markusritschel
Last active August 21, 2024 08:33
Show Gist options
  • Save markusritschel/226e64b8e5ba9e69d07de9d5afa8352a to your computer and use it in GitHub Desktop.
Save markusritschel/226e64b8e5ba9e69d07de9d5afa8352a to your computer and use it in GitHub Desktop.
Shortcut for compressing PDF files. Put this file in a directory that is in your $PATH. Then execute `pdfcompress -h` in your terminal for usage info.
#!/bin/bash
function myHelp () {
cat <<-END
Compresses a PDF file.
The output file will be named "inputfile_compressed.pdf".
Usage:
------
pdfcompress <QUALITY> <PDF_FILE>
QUALITY can be one out of [screen, ebook, printer, prepress]
PDF_FILE is the input file
Options:
--------
-h | --help Display this help
END
}
if [ -z "$1" ]; then
myHelp
exit;
else
case "$1" in
-h | --help)
myHelp
exit
;;
esac
# done
fi
# /// MAIN FUNCTION /// #
gs \
-dNOPAUSE \
-dBATCH \
-sDEVICE=pdfwrite \
-dPrinted=false \
-dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/${1} \
-dDownsampleColorImages=true \
-dColorImageResolution=150 \
-sOutputFile="${2%.pdf}_compressed.pdf" \
"${2}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment