Created
August 2, 2018 02:41
-
-
Save teebu/e91ad4ba995e82ac2c0b4c678425849e to your computer and use it in GitHub Desktop.
Remove blank pages from PDF
This file contains hidden or 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 | |
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