How to make an office scanner network

Lyrical digression


In one small organization (~ 10 computers) it was necessary to organize a backup of information. To do this, it was decided to install a computer with a large hard drive and Ubuntu inside, and Cobian backup on users' computers.

An inquisitive reader will ask: “Why are you writing this, author? And what does any scanner have to do with it? ”
The fact is that in this organization there was only one opportunity to scan a document - to ask it to make the happy owner of the Samsung SCX-4200 MFP (the name, of course, is unprincipled, but it all happened because of this device).
During the installation of Ubuntu on the “server for backup”, the idea came up: “And if you connect this MFP here, leave the keyboard connected, and by pressing certain keys make the scanner scan, saving the result in a shared folder? After all, then a person will not be distracted from work to scan other people's documents! ”
Of course, first of all, ready-made scripts were searched. This one seemed most interesting - www.opennet.ru/base/sys/net_scanner.txt.html
However, upon closer inspection, it turned out to be not so good, because I have absolutely no desire to recompile the program to change the scanner settings, to teach users how to convert images and create .pdf files.
I’ll try to write my own, good ...


So, the task is set


1. Connect an MFP to Ubuntu, make the printer shared, configure the scanner.
2. Write a script that will wait for a keystroke on the
Esc key - cancel the incomplete scan
1 - scan mode in color
2 - scan mode in grayscale
0 - save the scanned file (jpg if one page was scanned or pdf if several)
Enter - scan the page.

Decision


Point 1 dropped by itself. Connecting the printer was unexpectedly simple and did not raise a single question. It was enough just to connect the USB cable to the computer, and after a few seconds Ubuntu announced that the printer should print. I sent a test page - it really prints!
Now the fun part.
Let's see what scanners we have in the system:
scanimage -L
If the system cannot find this command, it means you need to install the sane-utils package:
sudo apt-get install sane-utils

The program found a device named `xerox_mfp: libusb: 001: 002`
If the scanner is the only one in the system, the “device name” parameter can be omitted; scanimage will scan the only possible scanner.

Let's try to scan the page:
scanimage -d “xerox_mfp: libusb: 001: 002” --resolution 150 --mode Color --format = tiff> test.tif
Resolution of 150 dpi was chosen because of the desire to reduce the scan time and size of the output file, but leave it to the user the ability to print a document with readable text. If you ever need text recognition or photo scanning, then additional options will appear.
So we have tiff. Either one or several (scanned multi-page document). It is clear that users in 90% of cases scan documents for sending by e-mail, and tiff is not a compact format. So, you need to convert the result to .jpg or .pdf.

We put a package for editing / converting raster images:
sudo apt-get install imagemagick

We compress a single image:
convert -quality 60% test.tif test.jpg

Or all at once:
convert -compress jpeg -quality 60% * .tif all.pdf

Only one thing remains . I am not going to leave a monitor connected to this computer - which means that the user remains without feedback. Well, let's make the computer talk.
Make a list of sounds that should be played in response to pressing a particular key on the keyboard, pick up a microphone and record our mini-phrases. They are as short as possible in time, because the purpose of the whole action is not listening to mp3, but scanning.
1. Waiting for a command (waitcommand.mp3)
2. Color scanning (color.mp3)
3. Black and white scanning (bw.mp3)
4. Scanning a page (scanpage.mp3)
5. Save the result (saveresult.mp3)

Oh yes, because we have a “clean” system that cannot play mp3 from the console ... We
fix the situation:
sudo apt-get install mpg321
Enjoy:
mpg123 -q waitcommand.mp3

Now everything seems ready


We write the script /mnt/2tb/scan.sh We say chmod + x /mnt/2tb/scan.sh

#!/bin/bash

# ==================================================
# Настройки

scannerdevice="xerox_mfp:libusb:001:002" #scanimage -L
workdir="/tmp/scanworkdir"
destdir="/mnt/2tb/Share/1Scanner"
dpi="150"
jpegquality="60%"

# ==================================================
# Собственно скрипт

sleep 10s

mkdir -p $workdir
rm $workdir/*.* 2>/dev/null
numpages=0
color="Gray"
mpg123 -q waitcommand.mp3

while true
do
#Нажмите клавишу
read -sn 1 Keypress

case "$Keypress" in
$'\e')
#Жду команду
rm $workdir/*.* 2>/dev/null
numpages=0
color="Gray"
mpg123 -q waitcommand.mp3
;;

$'1')
#Цвет
color="Color"
mpg123 -q color.mp3
;;

$'2')
#Ч/б
color="Gray"
mpg123 -q bw.mp3
;;

$'0')
#Сканирование завершено
mpg123 -q saveresult.mp3
filename=`date +%Y%m%d-%H%M%S`
if [ $numpages = 1 ]; then
convert -quality $jpegquality $workdir/1.tif $destdir/$filename.jpg
fi
if [ $numpages \> 1 ]; then
convert -compress jpeg -quality $jpegquality $workdir/*.tif $destdir/$filename.pdf
fi
rm $workdir/*.* 2>/dev/null
numpages=0
color="Gray"
mpg123 -q waitcommand.mp3
;;

$'')
#Новая страница
mpg123 -q scanpage.mp3
let "numpages=numpages+1"
scanimage -d $scannerdevice --resolution $dpi --mode $color --format=tiff >$workdir/$numpages.tif
mpg123 -q waitcommand.mp3
;;
esac

done





We launch


Yes, everything works as expected. Now we go to the Ubuntu menu System -> Options -> Launched applications, Add, Browse, select the script file. We reboot the computer, and ... the scanner begins to continuously scan something, sounds are not reproduced.
Okay, I press Ctrl + C, I read what I wrote again ...
Everything is trivial with the sounds - they are not in the folder where the script is called from. Continuous scanning is apparently due to $ '') inside the case.

I did not deal with this in detail, but simply changed the autorun command to
/ usr / bin / gnome-terminal -e /mnt/2tb/scan.sh --working-directory / mnt / 2tb
I restart the computer again - everything works, users satisfied.

Also popular now: