-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscanner-doc
More file actions
executable file
·54 lines (46 loc) · 1.08 KB
/
Copy pathscanner-doc
File metadata and controls
executable file
·54 lines (46 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
# Utility for making quick scans for documents, all pages combined into a
# single OCR'ed PDF. Also check out tiff2pdf and pdfsandwich
# TODO djvu
set -euo pipefail
DPI=150
TMP=$(mktemp -d "${TMPDIR:-/tmp}/$(basename "$0").XXXXX")
function finalize {
rm -rf "${TMP}"
}
trap finalize EXIT
ARGS=(
-colorspace gray
#-sigmoidal-contrast 20,50%
#-posterize 8
)
SCANS=()
while true; do
echo "Starting scan..." >&2
SCAN="$(mktemp --tmpdir="$TMP" --dry-run "XXXXX.pdf")"
scanimage \
--progress \
--resolution ${DPI} \
-l 2 -t 2 -x 213 -y 295 \
--format tiff \
| convert TIFF:- \
-strip \
"${ARGS[@]}" \
-background white \
-page a4 \
PDF:- \
| ocrmypdf - "$SCAN"
if [ $? -eq 0 ]; then
echo "Scan finished." >&2
SCANS+=("${SCAN}")
else
echo "Scan failed." >&2
fi
read -r -p "Add another page? [Y/n]" confirm
case $confirm in
[nN]*) break ;;
*) continue ;;
esac
done
# Combine pages
pdftk ${SCANS[@]} cat output "${1:-untitled}"