Fix unsuccessful scan issue and optimize postprocessing

This commit is contained in:
Timo Tomasini 2023-07-25 23:20:35 +02:00
parent 5031b15fdf
commit 14c7038b49

View file

@ -7,20 +7,27 @@ DATE=$(date +"%Y-%m-%dT%H%M%S")
outdir=/var/spool/scan/out outdir=/var/spool/scan/out
outname=$DATE.pdf outname=$DATE.pdf
tmpdir=/tmp/scan-$RANDOMNUMBER tmpdir=/tmp/scan-$RANDOMNUMBER
rotatepagesthreshold=10.0
cloudsendpass="" cloudsendpass=""
cloudsendurl="" cloudsendurl=""
source $SCRIPTPATH/scan.script.env source $SCRIPTPATH/scan.script.env
clean_up() {
echo "##### Cleaning up $tmpdir #####"
rm -rf $tmpdir
}
echo "###### Begin of $SCANBD_ACTION for device $SCANBD_DEVICE ######" echo "###### Begin of $SCANBD_ACTION for device $SCANBD_DEVICE ######"
echo "###### TMPDIR $tmpdir ######" echo "###### TMPDIR $tmpdir ######"
mkdir $tmpdir mkdir $tmpdir
echo "################## Scanning ###################" echo "################## Scanning ###################"
#scanimage --format tiff --mode Color --source "ADF Duplex" --resolution 300 --buffermode On --page-height 1000mm --ald=yes --swcrop=yes --swdeskew=yes --swdespeck 2 --swskip 8% --batch=p%03d.tiff #scanimage --device-name $SCANBD_DEVICE --format tiff --mode Color --source "ADF Duplex" --resolution 300 --buffermode On --page-height 1000mm --ald=yes --swcrop=yes --swdeskew=yes --swdespeck 2 --swskip 8% --batch=$tmpdir/p%03d.tiff
scanimage --device-name $SCANBD_DEVICE --format tiff --mode Color --source "ADF Duplex" --resolution 300 --buffermode On --page-width 210mm --page-height 297mm --ald=no --swcrop=no --swdespeck 1 --swskip 8% --batch=$tmpdir/p%03d.tiff scanimage --device-name $SCANBD_DEVICE --format tiff --mode Color --source "ADF Duplex" --resolution 300 --brightness 16 --buffermode On --page-width 210mm --page-height 297mm --ald=no --swcrop=no --swdespeck 2 --swskip 8% --batch=$tmpdir/p%03d.tiff
if [ ! -f "$tmpdir/p001.pdf" ]; then if [ ! -f "$tmpdir/p001.tiff" ]; then
echo "#### Scan was not successful, aborting ... ####" echo "#### Scan was not successful, aborting ... ####"
clean_up
exit 1 exit 1
fi fi
@ -30,7 +37,7 @@ tiff2pdf -o $tmpdir/tiff2pdf.pdf -z -u m -p "A4" -F $tmpdir/combined.tiff
echo "########## OCRing and optimizing PDF ##########" echo "########## OCRing and optimizing PDF ##########"
mkdir -p $outdir mkdir -p $outdir
ocrmypdf -l eng+deu --rotate-pages --deskew --clean $tmpdir/tiff2pdf.pdf $outdir/$outname ocrmypdf -l eng+deu --deskew --clean --rotate-pages --rotate-pages-threshold $rotatepagesthreshold $tmpdir/tiff2pdf.pdf $outdir/$outname
echo "############# Attempting upload ###############" echo "############# Attempting upload ###############"
CLOUDSEND_PASSWORD=$cloudsendpass cloudsend -p $outdir/$outname $cloudsendurl CLOUDSEND_PASSWORD=$cloudsendpass cloudsend -p $outdir/$outname $cloudsendurl
@ -39,9 +46,5 @@ if [ $? -eq 0 ]; then
rm -f $outdir/$outname rm -f $outdir/$outname
fi fi
clean_up
echo "##### Cleaning up $tmpdir #####"
rm -rf $tmpdir
echo "######## Finished scan $outname ########" echo "######## Finished scan $outname ########"