Skip to content

Instantly share code, notes, and snippets.

@gongzhitaao
Created March 10, 2017 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gongzhitaao/1544581b4cb994bfce4a129511ec6c56 to your computer and use it in GitHub Desktop.
Save gongzhitaao/1544581b4cb994bfce4a129511ec6c56 to your computer and use it in GitHub Desktop.
Useful PDF editing scripts.
#!/bin/bash
# Convert PDF to grayscale: http://superuser.com/q/104656/149756
if [ $# -ne 2 ]; then
echo $0: usage: pdf2gray input output
exit 1
fi
input=$1
output=$2
gs \
-sOutputFile=$output \
-sDEVICE=pdfwrite \
-sColorConversionStrategy=Gray \
-dProcessColorModel=/DeviceGray \
-dCompatibilityLevel=1.4 \
-dNOPAUSE \
-dBATCH \
$input
#!/bin/bash
hash gs 2>/dev/null || {
echo >&2 "I require gs but it's not installed."
return
}
if [ $# -lt 3 ]; then
echo >&2 "Require at least two inputs and one output file."
return
fi
src=${@:1:$(($#-1))}
des=${@:$#}
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite \
-sOutputFile=$des $src

This repo collects convenient scripts.

  1. graypdf. Convert PDF to grayscale.
  2. mergepdf. Merge a sequence of PDF files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment