-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from PhilippMundhenk/pedropombeiro/remove-blanks
Add support for removing of blank pages
- Loading branch information
Showing
4 changed files
with
95 additions
and
32 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash | ||
# remove_blank - git.waldenlabs.net/calvinrw/brother-paperless-workflow | ||
# Heavily based on from Anthony Street's (and other contributors') | ||
# StackExchange answer: https://superuser.com/a/1307895 | ||
|
||
if [ -n "$REMOVE_BLANK_THRESHOLD" ]; then | ||
IN="$1" | ||
FILENAME="$(basename "${IN}")" | ||
FILENAME="${FILENAME%.*}" | ||
SCRIPTNAME="remove_blank.sh" | ||
PAGES="$(pdfinfo "$IN" | grep ^Pages: | tr -dc '0-9')" | ||
echo "$SCRIPTNAME: threshold=$REMOVE_BLANK_THRESHOLD; analyzing $PAGES pages" | ||
|
||
cd "$(dirname "$IN")" || exit | ||
pwd | ||
|
||
function non_blank() { | ||
for i in $(seq 1 "$PAGES"); do | ||
PERCENT=$(gs -o - -dFirstPage="${i}" -dLastPage="${i}" -sDEVICE=ink_cov "$IN" | grep CMYK | nawk 'BEGIN { sum=0; } {sum += $1 + $2 + $3 + $4;} END { printf "%.5f\n", sum } ') | ||
if [ $(echo "$PERCENT > $REMOVE_BLANK_THRESHOLD" | bc) -eq 1 ]; then | ||
echo "$i" | ||
echo "Page $i: keep" 1>&2 | ||
else | ||
echo "Page $i: delete" 1>&2 | ||
fi | ||
done | tee "$FILENAME.tmp" | ||
} | ||
|
||
set +x | ||
pdftk "${IN}" cat $(non_blank) output "${FILENAME}_noblank.pdf" && | ||
mv "${FILENAME}_noblank.pdf" "$IN" | ||
fi |
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