[sane-devel] pdf (double-side scanning via adf)

Jens Gulden mail at jensgulden.de
Tue Oct 30 17:49:14 UTC 2007


Hello,

Julien BLACHE schrieb:
>> I think you've just reinvented scanimage --batch-prompt :-)

Oops, yes. But you must admit it's a useful 'invention' :-).

The script originated from a more complex thing: double-side scanning of multiple pages via adf (see 
below).
It first scans a pile of pages on one side, then the pile is turned around and the other sides are 
scanned. Finally, the script re-sorts the page numbers so that subsequent pages appear in the right 
order again (which is a bit tricky because the second sides got scanned in reverse order).

Is there an option in scanadf or another tool in sane-utils which does about the same? Would be 
useful, I guess.

best,
Jens

### script start ###

MODE="Black & White"
RESOLUTION=300
PREFIX=page
DIGITS=4
SUFFIX=.pbm
FLAGFILE=./_DOUBLESIDE
VERBOSE="-v" # set to '-v' to get verbose output

red='\e[0;31m'
green='\e[0;32m'
blue='\e[0;34m'
cyan='\e[0;36m'
yellow='\e[0;33m'
nc='\e[0m' # No Color

while [ -z "" ]; do  # endless

   I=1
   J="0001"

   # find first unused file number

   while [ -f $PREFIX${J:(-$DIGITS)}$SUFFIX ]; do
     I=$(( I + 1 ))
     J="000$I"
   done

   if [ -f $FLAGFILE ]; then
     DOUBLESIDE=`cat $FLAGFILE`
   else
     DOUBLESIDE=""
   fi

   if (( DOUBLESIDE )); then
     echo
     echo -e "${red}------ SECOND SIDE BATCH ------"
     echo
   else
     echo -e "${green}"
   fi

   if (( I==1 )); then
     echo -n "Starting"
   else
     echo -n "Continuing"
   fi
   echo -n " ADF scan "
   if (( DOUBLESIDE )); then
     echo -n "in DOUBLE-SIDE MODE "
   fi
   echo "at page number $I, file: $PREFIX${J:(-$DIGITS)}$SUFFIX."

   echo -n "Please press <RETURN> to "
   if (( I==1 )); then echo -n "start"; else echo -n "continue"; fi
   if (( DOUBLESIDE )); then
     DOUBLESIDECOUNT=$((I-DOUBLESIDE))
     echo -n " with second side batch ($DOUBLESIDECOUNT sheets, beginning with sheet $DOUBLESIDE), 
<1> to cancel double-side mode"
   else
     echo -n ", <2> to enter double-side mode"
   fi
   echo ", or ctrl-c to quit."

   read CMD

   if (( DOUBLESIDE )); then

     if [[ $CMD == "1" ]]; then
       echo -e "${green}Double-side mode canceled, continuing with single-side scans."
       rm $FLAGFILE
       DOUBLESIDE=""
     else
       echo "Continue double-side scanning..."
     fi

   else

     if [[ $CMD == "2" ]]; then
       echo -e "${red}DOUBLE-SIDE mode beginning with sheet $I."
       echo $I > $FLAGFILE # remember start of double-side batch
     else
       echo "Continue scanning..."
     fi

   fi

   scanadf -s $I -o $PREFIX%0${DIGITS}d$SUFFIX --mode "$MODE" --resolution $RESOLUTION

   if (( DOUBLESIDE )); then # was second-side pass

     L=$(( I + DOUBLESIDECOUNT - 1 ))
     LAST="000$L"
     if [[ -f $PREFIX${LAST:(-$DIGITS)}$SUFFIX ]]; then

       if (( DOUBLESIDECOUNT > 1 )); then

         # make correct order of recently scanned pages
         if [[ -n $VERBOSE ]]; then echo "Correcting order of double-side scans:"; fi
         c=$DOUBLESIDECOUNT
         for (( j = DOUBLESIDE; j < (DOUBLESIDE + ((DOUBLESIDECOUNT - 1) * 2) ); j = (j + 2) )); do
           # shift one step to make space
           m=$(( j + c*2 ))
           c=$(( c - 1 ))
           n=$m
           if [[ -n $VERBOSE ]]; then echo "shifting $(( n - j - 1 )) files..."; fi
           while (( n > (j+1) )); do
             k=$((n-1))
             FROM="000$k"
             TO="000$n"
             mv $PREFIX${FROM:(-$DIGITS)}$SUFFIX $PREFIX${TO:(-$DIGITS)}$SUFFIX
             n=$k
           done
           # move wanted second page to its correct position
           FROM="000$m"
           jj=$((j+1))
           TO="000$jj"
           #if [[ -n $VERBOSE ]]; then echo -n "--> "; fi
           mv $VERBOSE $PREFIX${FROM:(-$DIGITS)}$SUFFIX $PREFIX${TO:(-$DIGITS)}$SUFFIX
         done

       fi

       # done
       rm $FLAGFILE

     else

       echo "Problem: file $PREFIX${LAST:(-$DIGITS)}$SUFFIX not found, should be last file scanned 
in second-side batch."
       echo -e "${red}ABORTING now, please fix an run $0 again."
       exit 1

     fi

   fi

done

### script end ###


> Jens Gulden <mail at jensgulden.de> wrote:
> 
> Hi,
> 
> 
>>In case you're on Linux/command-line, you may want to look at the script I use to scan multiple 
>>pages in sequence. It waits for a hit on <return> after each page:
> 
> 
> I think you've just reinvented scanimage --batch-prompt :-)
> 
> JB.
> 




More information about the sane-devel mailing list