Skip to content

Instantly share code, notes, and snippets.

@mgbckr
Last active February 28, 2018 16:26
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 mgbckr/28679d827a306075ee2fd24b4a37dcf8 to your computer and use it in GitHub Desktop.
Save mgbckr/28679d827a306075ee2fd24b4a37dcf8 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# colorpages_printstring.bash
#
# Tool to print only color pages from a PDF (duplex).
# Generates a string to be used for common printing dialogs which only contains pages (back and front) with color.
#
# usage: colorpages_printstring <your>.pdf
#
# requirements: ghostscript (gs)
#
# TODO: Remove duplicates
pages=`gs -o - -sDEVICE=inkcov $1 |sed '/^Page*/N;s/\n//'|grep -v -e '0.00000 0.00000 0.00000' |grep Page|sed 's/Page \([0-9]*\).*/\1/g'`
ranges=()
for i in ${pages}; do
if (( $i % 2 )); then
ranges+=($i-$((i+1)))
else
ranges+=($((i-1))-$i)
fi
done
string=$(printf ",%s" "${ranges[@]}")
string=${string:1}
echo $string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment