+errlog()
+{
+ local lastexit=$?
+ local msg="$1"
+
+ echo "❌ ERROR: $msg"
+ echo "🛑 EXIT $lastexit"
+ return $lastexit
+}
+
optimize()
{
local input=$1
local output=$input-out
+ command -v qpdf > /dev/null \
+ || errlog "command qpdf not found" \
+ || return $?
qpdf --linearize $input $output \
|| errlog "could not linearize $input" \
- || return 1
+ || return $?
mv $output $input \
|| errlog "cloud not rename $ouptut to $input" \
- || return 1
+ || return $?
}
addocr()
local output=$input-out
local error=""
+ command -v ocrmypdf > /dev/null \
+ || errlog "command ocrmypdf not found" \
+ || return $?
echo $input
error=$(ocrmypdf -l deu $input $output 2>&1) \
|| errlog "could not add ocr on $input" \
- || return 1
+ || return $?
if [ -n "$(echo $error | grep offset)" ]; then
printf "%s: %s\n" $input $error >> $HOME/addocr-error.log
if [ -f $output ]; then
mv $output $input \
|| errlog "could not rename $output to $input" \
- || return 1
- optimize $input || return 1
+ || return $?
+ optimize $input || return $?
fi
}
{
local output=$1
+ command -v tiff2pdf > /dev/null \
+ || errlog "command tiff2pdf not found" \
+ || return $?
+ command -v pdftk > /dev/null \
+ || errlog "command pdftk not found" \
+ || return $?
for i in scanned*.tiff; do
tiff2pdf $i -o ${i/.tiff/.pdf} \
|| errlog "could not convert tiff to pdf" \
- || return 1
- rm $i || errlog "could not delete $i" || return 1
+ || return $?
+ rm $i || errlog "could not delete $i" || return $?
done
pdftk scanned*.pdf output $output \
|| errlog "could not convert into single $output" \
- || return 1
+ || return $?
rm scanned*.pdf \
|| errlog "could not remove scanned pdfs" \
- || return 1
- addocr $output || return 1
+ || return $?
+ addocr $output || return $?
}
createpdf()
local countno=
local pdfs=()
+ command -v pdftk > /dev/null \
+ || errlog "command pdftk not found" \
+ || return $?
+
if [ -z "$basename" ]; then
basename="out"
fi
local endcount=1
local pdf=
+ command -v tiff2pdf > /dev/null \
+ || errlog "command tiff2pdf not found" \
+ || return $?
for i in scanned*.tiff; do
pdf=${i/.tiff/.pdf}
tiff2pdf $i -o $pdf \