-
Notifications
You must be signed in to change notification settings - Fork 1
/
merge-scanned-docs
executable file
·58 lines (51 loc) · 1.22 KB
/
merge-scanned-docs
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
55
56
57
58
#!/bin/bash
# prints help text
# exits 0
help() {
echo "merges double printed documents scanned twice";
echo "usage: merge-scanned-docs <docpath>";
echo "assumes two PDFs named <docpath>_odd.pdf and <docpath>_even.pdf";
echo "assumes that <docpath>_even.pdf is in reverse order";
echo "generates a new PDF named <docpath>.pdf";
exit 0;
}
# checks if a file or directory exists
# param 1: the file to check
# returns 0: if the file or directory doesn't exist
# exits 1: if the file or directory exists
checkF() {
if [ -f "$1" ]; then
echo "file '$1' already exists. aborting".
exit 1;
fi
return 0;
}
# checks reada access of a file
# param 1: the file to check
# returns 0: if the file exist
# exits 1: if the file either doesn't exist or no read permission are granted
checkR() {
if [ ! -e "$1" ]; then
echo "file '$1' not found. aborting.";
exit 1;
fi
if [ ! -r "$1" ]; then
echo "no read permission for file '$1' granted. aborting.";
exit 1;
fi
return 0;
}
# start
if [ -z "$1" ]; then
help;
fi
# build 3 filenames
inA="$1_odd.pdf";
inB="$1_even.pdf";
out="$1.pdf";
# check files
checkR $inA;
checkR $inB;
checkF $out;
# merge files
pdftk A="$inA" B="$inB" shuffle A Bend-1 output "$out";