Recently Written · git

sh

Small shell and Python scripts

git clone https://github.com/equwal/sh

Log | Files | Refs


group4ify (467 bytes)

1 #!/bin/sh
2 # Recompress every page of a scanned PDF as bilevel CCITT Group 4 (via group4ify-aux).
3 # Usage: group4ify FILE.pdf   (writes ./FILE.pdf-group4.pdf)
4 set -e
5 TEMP="$(mktemp -d)"
6 trap 'rm -r "$TEMP"' EXIT
7 OUT="$PWD/$(basename "$1")-group4.pdf"
8 pdfseparate "$1" "$TEMP"/%d.pdf
9 
10 cd "$TEMP"
11 for p in *.pdf; do group4ify-aux "$p"; done
12 # shellcheck disable=SC2046 # page files are N.pdf-group4.pdf: no spaces
13 pdfunite $(printf '%s\n' *-group4.pdf | sort -n) "$OUT"