From 190434c03913a1df90f151ab5a2da60d6eabe5b8 Mon Sep 17 00:00:00 2001 From: Timo Tomasini Date: Mon, 24 Jul 2023 14:40:41 +0200 Subject: [PATCH] Initial commit --- .gitignore | 2 ++ scan.script | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 .gitignore create mode 100755 scan.script diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2daf530 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.env +out/ diff --git a/scan.script b/scan.script new file mode 100755 index 0000000..54784d3 --- /dev/null +++ b/scan.script @@ -0,0 +1,38 @@ +#!/bin/bash + +outdir=/var/spool/scan/out +RANDOMNUMBER=$(cat /dev/urandom | tr -dc A-Za-z0-9 | head -c${1:-16}) +DATE=$(date +"%Y-%m-%dT%H%M%S") +outname=$DATE.pdf +tmpdir=/tmp/scan-$RANDOMNUMBER +cloudsendpass="" +cloudsendurl="" +source ./scan.script.env + +echo "######## TMPDIR $tmpdir ########" +mkdir $tmpdir + +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 --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 + +echo "############# Converting to PDF ###############" +tiffcp -c lzw $tmpdir/*.tiff $tmpdir/combined.tiff +tiff2pdf -o $tmpdir/tiff2pdf.pdf -z -u m -p "A4" -F $tmpdir/combined.tiff + +echo "########## OCRing and optimizing PDF ##########" +ocrmypdf -l eng+deu --rotate-pages --deskew --clean $tmpdir/tiff2pdf.pdf $outdir/$outname + +echo "############# Attempting upload ###############" +CLOUDSEND_PASSWORD=$cloudsendpass cloudsend -p $outdir/$outname $cloudsendurl + +if [ $? -eq 0 ]; then + rm -f $outdir/$outname +fi + + +echo "######## Cleaning up $tmpdir ########" +rm -rf $tmpdir + +echo "######## Finished scan $outname ########" +