Skip to content

Instantly share code, notes, and snippets.

@ksm2
Created May 4, 2017 13:36
Show Gist options
  • Save ksm2/bfa5139956f47c5c482eac83f25c06db to your computer and use it in GitHub Desktop.
Save ksm2/bfa5139956f47c5c482eac83f25c06db to your computer and use it in GitHub Desktop.
#!/bin/bash
FILE=$1
PAGES=$(pdfinfo ${FILE} | grep 'Pages:' | sed 's/Pages:\s*//')
GRAYPAGES=""
COLORPAGES=""
EMPTYPAGES=""
echo -e "\e[1mPages:\e[0m $PAGES"
N=1
while (test "$N" -le "$PAGES")
do
CMYK=$( gs -q -o - -sDEVICE=inkcov -dFirstPage=$N -dLastPage=$N "$FILE" )
CYAN=$(echo $CMYK | cut -d' ' -f1)
MAGENTA=$(echo $CMYK | cut -d' ' -f2)
YELLOW=$(echo $CMYK | cut -d' ' -f3)
BLACK=$(echo $CMYK | cut -d' ' -f4)
if [ $CYAN == "0.00000" ]
then
if [ $MAGENTA == "0.00000" ]
then
if [ $YELLOW == "0.00000" ]
then
if [ $BLACK == "0.00000" ]
then
EMPTYPAGES="$EMPTYPAGES $N"
GRAYPAGES="$GRAYPAGES $N"
# echo "Page $N: empty"
else
GRAYPAGES="$GRAYPAGES $N"
# echo "Page $N: grey"
fi
else
COLORPAGES="$COLORPAGES $N"
# echo "Page $N: coloured"
fi
else
COLORPAGES="$COLORPAGES $N"
# echo "Page $N: coloured"
fi
else
COLORPAGES="$COLORPAGES $N"
# echo "Page $N: coloured"
fi
N=$((N+1))
done
echo -e "\e[1mEmpty:\e[0m $(echo $EMPTYPAGES | wc -w)"
echo $EMPTYPAGES
echo -e "\e[1mGrey:\e[0m $(echo $GRAYPAGES | wc -w)"
echo $GRAYPAGES
echo -e "\e[1mColoured:\e[0m $(echo $COLORPAGES | wc -w)"
echo $COLORPAGES
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment