Skip to content

Instantly share code, notes, and snippets.

@pirpyn
Last active February 24, 2020 14:30
Show Gist options
  • Save pirpyn/3a9e9e2becd92abd9713675b1c507b23 to your computer and use it in GitHub Desktop.
Save pirpyn/3a9e9e2becd92abd9713675b1c507b23 to your computer and use it in GitHub Desktop.
pdf tools for linux using ghostscript
#!/bin/bash
usage () { cat << EOF
usage : pdfcompress [ -q id ] file.pdf
options : -q id
0 screen (screen-view-only quality, 72 dpi images)
1 default (almost identical to /screen)
2 ebook (low quality, 150 dpi images)
3 printer (high quality, 300 dpi images)
4 prepress (high quality, color preserving, 300 dpi imgs)
EOF
}
OPTIND=1
while getopts 'q:h' arg; do
case ${arg} in
h)
usage
exit 1
;;
q)
id=${OPTARG}
;;
esac
done
shift $((${OPTIND} - 1 ))
qualities=(screen default ebook printer prepress)
case ${id} in
screen) id=0;;
default) id=1;;
ebook) id=2;;
printer) id=3;;
prepress) id=4;;
0|1|2|3|4) id=${id} ;;
*) id=2 ;;
esac
if [[ $# -ne 1 ]]; then
usage
exit 1
else
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dPDFSETTINGS=/${qualities[id]} -sOutputFile=${1/.pdf/_q${id}.pdf} $1
exit $?
fi
#!/bin/bash
usage () { cat << EOF
usage : pdfmerge [ -q prepress ] merged.pdf file1.pdf ...
options : -q quality
screen (screen-view-only quality, 72 dpi images)
ebook (low quality, 150 dpi images)
printer (high quality, 300 dpi images)
prepress (high quality, color preserving, 300 dpi imgs)
default (almost identical to /screen)
EOF
}
OPTIND=1
while getopts 'q:h' arg; do
case ${arg} in
h)
usage
exit 1
;;
q)
quality=${OPTARG}
;;
esac
done
shift $((${OPTIND} - 1 ))
quality=${quality:-prepress}
if [[ $# -le 1 ]]; then
usage
exit 1
else
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dPDFSETTINGS=/${quality} -sOutputFile=$@
exit $?
fi
#!/bin/bash
usage () { cat << EOF
usage : pdfsplit [ -q prepress ] input.pdf first_page last_page output.pdf
options : -q quality
screen (screen-view-only quality, 72 dpi images)
ebook (low quality, 150 dpi images)
printer (high quality, 300 dpi images)
prepress (high quality, color preserving, 300 dpi imgs)
default (almost identical to /screen)
EOF
}
OPTIND=1
while getopts 'q:h' arg; do
case ${arg} in
h)
usage
exit 1
;;
q)
quality=${OPTARG}
;;
esac
done
shift $((${OPTIND} - 1 ))
quality=${quality:-prepress}
if [ $# -ne 4 ]; then
usage
exit 1
else
gs -dBATCH -dNOPAUSE -q -dPDFSETTINGS=/${quality} -sOutputFile="$4" -dFirstPage="$2" -dLastPage="$3" -sDEVICE=pdfwrite "$1"
exit $?
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment