[linux-l] Fax-datei vom Scanner einlesen?
Schlomo Schapiro
belug at schlomo.schapiro.org
Di Jan 6 11:13:29 CET 2004
Hallo,
mein script ist anbei, musste vielleicht noch an Deine Faxsoftware
anpassen. Sonst kann ich xsane empfehlen.
Schlomo
On Tue, 6 Jan 2004 mail at ekaiser.de wrote:
> Liebe Liste,
>
> ich möchte mit der capisuite Faxe versenden. Wenn es nur
> ein Blatt ist, ist die Sache einfach: Einlesen, in
> ps-Format umwandeln und versenden.
>
> Wenn ich jetzt aber mehrere Blätter verschicken will, muß
> ich jedes einzelne einlesen, umwandeln und verschicken.
> Meine Frage: Kennt jemand ein Frontend, das Blätter vom
> Scanner liest und daraus eine einzige ps-Datei erstellt?
> Oder hat jemand schon ein kleines Skript für diesen Zweck
> geschrieben?
>
> Vielen Dank im voraus
> Erwin
>
> _______________________________________________
> linux-l mailing list
> linux-l at mlists.in-berlin.de
> Die Mailingliste der BeLUG (Berliner Linux User Group)
>
> Wenn du diese Mailingliste abbestellen willst, gehe bitte auf
> https://mlists.in-berlin.de/mailman/listinfo/linux-l
> und trage dich dort bitte aus
>
--
Regards,
Schlomo
-------------- nächster Teil --------------
#!/bin/sh
# variables here
faxnumber=''
pagecount=0
threshold=65
status=""
# Set display if not given
[ "$DISPLAY" ] || export DISPLAY=geni:0
# Check wether there is a scanner on the SCSI bus
while ! grep -qi SCANNER /proc/scsi/scsi ; do
# no scanner found, rescan scsi bus
echo "No Scanner found. If it is switched off, please switch it on now"
# for root only: wait for keypress before scanning scsi
[ `id -u` -eq 0 ] && read -p "Press ENTER to continue..."
rescan-scsi-bus.sh ;
done
# static vars here (in caps)
scanner=/dev/`find-scanner |grep UMAX |sed 's/.*dev\///'`
[ -z "$scanner" ] && {
echo "ERROR: Could not find a scanner with find-scanner"
exit 255
}
SCAN=umax:$scanner
# the following is good for the header page, see in the puthead function for
# definition of header. NAME is up to 20 chars, FAXID up to 30
NAME="Schapiro"
FAXID="Phone: ++49 (0)30 / 81 82 03 33"
function puthead () {
# this function takes 4 arguments:
# in-file (g3) and outfile (g3), number of page, total number of pages
# it puts a fax-header on top of in-file and writes the result to out-file
printf "FAX from %-40s %-50s Page %-2d from %-2d\n" \
"$NAME" "$FAXID" "$3" "$4" \
| pbmtext |pbmpscale 3 | pbm2g3 | g3cat - "$1" >"$2"
}
function menu {
clear
cat <<EOF
ScanFax v 1.0 27.10.1999 Schlomo Schapiro
--------------------------------------------------------------------------------
EOF
echo -n "Pages collected: $pagecount"
if test -z "$faxnumber" ; then echo " ";
else echo -e "\tFAX number: $faxnumber" ;
fi
echo "Scanner parameters: Threshold=$threshold"
cat <<EOF
Choose one of the following options:
1 Add new page from scanner (Scans immediately with current parameters)
2 Advanced Scan (Change Parameters, Scan with Preview etc.)
3 Add new page from plain text (via enscript)
4 Add PostScript page
5 Delete last scanned page
6 Print page from collection
7 Show page from collection (on display $DISPLAY)
S Send all collected pages by fax
9 Continue later (keep collected pages and quit)
0 Quit (delete all collected pages)
EOF
[ "$status" ] || return
echo "--- Status --- Status --- Status --- Status --- Status --- Status --- Status ---"
echo -e "$status \n"
status=""
true ;
}
function init_main () {
if [ $# -gt 0 ] ; then
if { echo $* |grep -q help ; } ; then
cat <<EOF
ScanFax v1.0 by Schlomo Schapiro
Usage: scanfax [working dir]
Collects pages from scanner and plain text (file or pico) and ps and send
them to a fax recipient (or several).
the only option accepted can be the working dir of a previous scanfax
session in which case scanfax will continue this session.
EOF
exit 0 ;
fi
# check wether we got an option and assume it's a previous working dir
# or set a new dir
if [ -d "$1" ] ; then
tmp="$1" ;
if [ -f "$tmp/scanfax.settings" ] ; then
. "$tmp/scanfax.settings"
else
echo "ERROR: The specified Working directory ($tmp) is not"
echo "a suspended ScanFax working direcory"
exit 253 ;
fi
else
echo "ERROR: Specified Working directory ($1) does not exist"
exit 254 ;
fi
else
tmp="/tmp/scanfax.$$" ;
fi
# make sure that our temp dir exists, if not exit
[ -d "$tmp" ] || mkdir "$tmp" || {
set err=$?
echo "ERROR: Problem creating working dir: $tmp. Stopping"
exit "$err" ;
}
true ;
}
function addfromscanner {
scanimage -d $SCAN --mode lineart --threshold $threshold -x 210 -y 300 --resolution 200 >"$tmp/scan.pbm"
if [ $? -eq 0 ] ; then
# scan was successfull
let pagecount=pagecount+1
pbm2g3 "$tmp/scan.pbm" > "$tmp/page_${pagecount}_.g3"
else
status="ERROR: Could not scan the page. Nothing added to collection"
fi
[ -f "$tmp/scan.pbm" ] && rm -f "$tmp/scan.pbm"
}
function ps2g3 () {
gs -dNOPAUSE -dBATCH -r200 -sDEVICE=faxg3 -sOutputFile="$2" -q "$1"
return $? ;
}
function advancedscan {
true ;
}
function addfromtext {
read -p "Enter name of text file (press Enter to create a new text): "
if [ -r "$REPLY" -a -s "$REPLY" ] ; then
cp "$REPLY" "$tmp/text.txt"
else
read -p "Press Enter to start the editor. When finished press Ctrl-X to continue."
/usr/bin/pico_4.10 "$tmp/text.txt"
fi
if [ -s "$tmp/text.txt" ] ; then
enscript -B -f Times-Roman14 -1 -o "$tmp/text.ps" "$tmp/text.txt"
let pagecount=pagecount+1
ps2g3 "$tmp/text.ps" "$tmp/page_${pagecount}_.g3"
rm -f "$tmp/text.ps"
else
status="Warning ! Supplied text is empty. Nothing added to collection."
fi
}
function addfromps {
read -p "Enter PostScript file to add :"
[ "$REPLY" ] || { status="Operation canceled. Nothing added to collection."
return ; }
if [ -r "$REPLY" -a -s "$REPLY" ] ; then
let pagecount=pagecount+1
ps2g3 "$REPLY" "$tmp/page_${pagecount}_.g3"
[ $? -gt 0 ] && {
[ -e "$tmp/page_${pagecount}_.g3" ] && rm -f "$tmp/page_${pagecount}_.g3"
let pagecount=pagecount-1
status="Warning ! Could not convert your PostScript file. Nothing added." ;
}
else
status="Warning ! Could not read from file or file not found. File: $REPLY"
fi
}
function dellastpage {
[ "$pagecount" -lt 1 ] && { status="Nothing to delete." ; return ; }
rm -f "$tmp/page_${pagecount}_.g3"
let pagecount=pagecount-1
status="Successfully deleted last page."
}
function printpage {
[ "$pagecount" -le 0 ] && { status="Warning ! No pages in collection. Nothing to print" ; return ; }
read -p "Select page to print (1 -> ${pagecount}): "
if [ "$REPLY" -gt 0 -a "$REPLY" -le "$pagecount" ] ; then
puthead "$tmp/page_${REPLY}_.g3" "$tmp/print.g3" "$REPLY" "$pagecount"
g32pbm -d 300 "$tmp/print.g3" |pbmtolj -resolution 300 |lpr -Praw
rm -f "$tmp/print.g3"
else
status="Warning ! Entered page number ($REPLY) out of range (1 -> $pagecount) or not a number."
fi
}
function showpage {
[ "$pagecount" -le 0 ] && { status="Warning ! No pages in collection. Nothing to show" ; return ; }
read -p "Select page to show (1 -> ${pagecount}): "
if [ "$REPLY" -gt 0 -a "$REPLY" -le "$pagecount" ] ; then
puthead "$tmp/page_${REPLY}_.g3" "$tmp/print.g3" "$REPLY" "$pagecount"
g32pbm "$tmp/print.g3" | xv - &
rm -f "$tmp/print.g3"
status="Starting XV with page $REPLY on display $DISPLAY."
else
status="Warning ! Entered page number ($REPLY) out of range (1 -> $pagecount) or not a number."
fi
}
function sendpage {
[ "$pagecount" -le 0 ] && {
status="Warning: Nothing to send. Collect at least one page first" ;
}
# build paramline constisting of all files in the RIGHT order
# put FAX header on each page, keeping the source files _.g3 and creating
# send files _out.g3 that will be deleted after sending.
pages=""
count=1
while [ $count -le $pagecount ] ; do
puthead "$tmp/page_${count}_.g3" "$tmp/page_${count}_out.g3" "$count" "$pagecount"
pages="$pages $tmp/page_${count}_out.g3"
let count=count+1
done
dummy=""
[ "$faxnumber" ] && dummy="(Press Enter to keep \"${faxnumber}\")"
read -p "Enter Faxnumber ${dummy}: "
[ "$REPLY" ] && faxnumber=$REPLY
[ "$faxnumber" ] || {
status="Warning ! You have to provide a fax number to send the faxes to."
rm -f "$tmp/"*out.g3
return ;
}
read -p "Send $pagecount pages to $faxnumber ? [y|n]"
case $REPLY in
y|Y) /usr/sbin/sendfax -v "$faxnumber" $pages 2>&1|tee "$tmp/"sendfax.out
status=`cat "$tmp/"sendfax.out` ; rm "$tmp/"sendfax.out
# sleep 5
true ;;
*) status="Sending aborted." ;;
esac
rm -f "$tmp/"*out.g3
}
function suspend {
echo >"$tmp/scanfax.settings" "pagecount=$pagecount"
echo >>"$tmp/scanfax.settings" "faxnumber=\"$faxnumber\""
echo >>"$tmp/scanfax.settings" "threshold=$threshold"
echo "Suspending ScanFax. To continue start the program like this:"
echo "scanfax $tmp"
exit 0
}
function leave {
rm -Rf $tmp
echo "Thank you for using my ScanFax program. Schlomo Schapiro"
exit 0
}
init_main "$@"
while true ; do
menu
read -p "Your Choice: "
case $REPLY in
1) addfromscanner ;;
2) advancedscan ;;
3) addfromtext ;;
4) addfromps ;;
5) dellastpage ;;
6) printpage ;;
7) showpage ;;
s|S) sendpage ;;
9) suspend ;;
0) leave ;;
esac
done
Mehr Informationen über die Mailingliste linux-l