Skip to content

Instantly share code, notes, and snippets.

@robinp
Created September 29, 2015 10:01
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 robinp/6921f75882ce3cfd2ee9 to your computer and use it in GitHub Desktop.
Save robinp/6921f75882ce3cfd2ee9 to your computer and use it in GitHub Desktop.
Convert color image pdf to black and white pdf.
#!/bin/bash
INPDF=$1
OUTDIR=$2
ROT=$3
CONVOPTS=$4
INBASE=$(basename ${INPDF} .pdf)
TMP=$(mktemp -d)
pdfimages -j ${INPDF} ${TMP}/${INBASE} # emits ppm,pbm or jpg
for i in $(ls ${TMP}/${INBASE}-*.*)
do
convert ${CONVOPTS} -colorspace Gray -threshold 40% $i -compress zip $i.pdf
done
pdftk ${TMP}/${INBASE}-*.pdf cat output ${TMP}/${INBASE}-cat.pdf
[ ! -z $ROT ] && pdftk ${TMP}/${INBASE}-cat.pdf cat 1-end${ROT} output ${OUTDIR}/${INBASE}.pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment