Skip to content

Instantly share code, notes, and snippets.

@teebu
Created August 2, 2018 02:41
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 teebu/e91ad4ba995e82ac2c0b4c678425849e to your computer and use it in GitHub Desktop.
Save teebu/e91ad4ba995e82ac2c0b4c678425849e to your computer and use it in GitHub Desktop.
Remove blank pages from PDF
#!/bin/bash
IN="$1"
OUT="$2"
PAGES=$(pdfinfo $IN | grep ^Pages: | tr -dc '0-9')
non_blank() {
for i in $(seq 1 $PAGES)
do
# more color spectrum
#convert -density 46 "$IN[$((i-1))]" -define histogram:unique-colors=true -format %c histogram:info:- | wc -l
if [ $(convert -density 16 "$IN[$((i-1))]" +dither -colors 8 -depth 4 -define histogram:unique-colors=true -format %c histogram:info:- | wc -l) -ne 1 ]
then
echo $i
#echo -n $i 1>&2
fi
echo -n . 1>&2
done
echo 1>&2
}
set +x
pdftk $IN cat $(non_blank) output $OUT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment