๐Ÿ“ฆ nnako / scannertools

๐Ÿ“„ scan_feed_A4_200dpi_bw_ds_dark.sh ยท 127 lines
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127#
# get user's wish of document name
#

if [[ $# -ge 2 ]]; then
    pdf_filename=$2
else
    pdf_filename=scan
fi




#
# wait for user to place the document stack
#

read -p "PLEASE PUT PAGES WITH CONTENT FACING UP INTO THE FEEDER" -n1




#
# scan front pages in forward sequence
#

# unfortunately, when using ADF, the current implementation of SCANADF
# mismatches the PNM output in the way that subsequent tools like imagemagick
# cannot identify the necessaty file format. this seems to be the case when
# scanning with a y range of about 295 mm when more than 1 page is scanned.
# when scanning at a slightly lower y range, this effect is not visible anymore.
# so, instead of using the full range of 210x295 mm for a DIN A4 page, here,
# a reduced range of 210x291 mm is used.

scanadf --source=ADF --mode=Lineart --resolution=200 --brightness=100 --contrast=300 -x 210 -y 291 -o /home/pi/scan_%02d.pnm




#
# convert all scanned pages to PNG and rename files
#

let filecount=1
let maxfilecount=0
filenames=`ls ./*.pnm`
for f in $filenames; do

    # create basename
    filename=${f##*/}
    basename=${filename%%.*}
    echo "$f -> scan_$(printf %02d $filecount).png"

    # convert image and remove original file
    convert $f scan_$(printf %02d $filecount).png
    rm $f

    # counters
    let maxfilecount=$maxfilecount+1
    let filecount=$filecount+2

done




#
# wait for user to place the document stack
#

read -p "PLEASE PUT PAGES WITH CONTENT TOP FACING DOWN INTO THE FEEDER" -n1




#
# scan back pages in forward sequence
#

# unfortunately, when using ADF, the current implementation of SCANADF
# mismatches the PNM output in the way that subsequent tools like imagemagick
# cannot identify the necessaty file format. this seems to be the case when
# scanning with a y range of about 295 mm when more than 1 page is scanned.
# when scanning at a slightly lower y range, this effect is not visible anymore.
# so, instead of using the full range of 210x295 mm for a DIN A4 page, here,
# a reduced range of 210x291 mm is used.

scanadf --source=ADF --mode=Lineart --resolution=200 --brightness=100 --contrast=300 -x 210 -y 291 -o /home/pi/scan_%02d.pnm




#
# convert all scanned pages to PNG and rename files
#

let filecount=$maxfilecount*2
filenames=`ls ./*.pnm`
for f in $filenames; do

    # create basename
    filename=${f##*/}
    basename=${filename%%.*}
    echo "$f -> scan_$(printf %02d $filecount).png"

    # convert image and remove original file
    convert $f scan_$(printf %02d $filecount).png
    rm $f

    # counters
    let filecount=$filecount-2

done




#
# convert to PDF
#

convert scan_*.png $pdf_filename.pdf
rm scan_*.png

# move into nextcloud
mv $pdf_filename.pdf ~/NEXTCLOUD/_scan/