Created
September 29, 2015 10:01
-
-
Save robinp/6921f75882ce3cfd2ee9 to your computer and use it in GitHub Desktop.
Convert color image pdf to black and white pdf.
This file contains 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
#!/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