From e87353ce35b28e57bb8414df841a3ab2aa6dc3e7 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Fri, 3 Apr 2026 14:26:56 +0200 Subject: [PATCH] change add ocr extra file --- Makefile | 3 ++- src/addocr.sh | 41 +++++++++++++++++++++++++++++++++++++++++ src/scanbasic.sh | 43 +------------------------------------------ 3 files changed, 44 insertions(+), 43 deletions(-) create mode 100644 src/addocr.sh diff --git a/Makefile b/Makefile index 8765641..36a30c4 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ SHAREDIR = usr/local/share all: test package -test: +test: $(BUILDDIR)/parts/scanbasic.sh ./tests/scanbasic.bats build: $(PACKAGEDIR)/$(BINDIR)/scantopdf \ @@ -31,6 +31,7 @@ clean: ################################################################################ $(BUILDDIR)/parts/scanbasic.sh: \ + $(SRCDIR)/addocr.sh \ $(SRCDIR)/scanbasic.sh mkdir -p $(@D) diff --git a/src/addocr.sh b/src/addocr.sh new file mode 100644 index 0000000..8997962 --- /dev/null +++ b/src/addocr.sh @@ -0,0 +1,41 @@ +optimize() +{ + local input="$1" + local output="$input-out" + + [ -n "$input" ] \ + || errlog "missing input" \ + || return $? + + qpdf --linearize $input $output \ + || errlog "could not linearize $input" \ + || return $? + mv $output $input \ + || errlog "could not rename $output to $input" \ + || return $? +} + +addocr() +{ + local input="$1" + local jobs="$2" + local output="$input-out" + jobs=${jobs:=1} + + [ -n "$input" ] \ + || errlog "missing input" \ + || return $? + + echo "ℹ️ INFO: adding ocr on file $input" + ocrmypdf --quiet --jobs $(nproc) --language deu $input $output \ + || errlog "could not add ocr on $input" \ + || return $? + + [ ! -f $output ] && return 0 + + mv $output $input \ + || errlog "could not rename $output to $input" \ + || return $? + optimize $input \ + || return $? +} diff --git a/src/scanbasic.sh b/src/scanbasic.sh index 7eeb2a3..db199ac 100644 --- a/src/scanbasic.sh +++ b/src/scanbasic.sh @@ -1,3 +1,4 @@ +#include "addocr.sh" errlog() { local lastexit=$? @@ -48,48 +49,6 @@ convert_tiff_to_pdf() rm $tiff } -optimize() -{ - local input="$1" - local output="$input-out" - - [ -n "$input" ] \ - || errlog "missing input" \ - || return $? - - qpdf --linearize $input $output \ - || errlog "could not linearize $input" \ - || return $? - mv $output $input \ - || errlog "could not rename $output to $input" \ - || return $? -} - -addocr() -{ - local input="$1" - local jobs="$2" - local output="$input-out" - jobs=${jobs:=1} - - [ -n "$input" ] \ - || errlog "missing input" \ - || return $? - - echo "ℹ️ INFO: adding ocr on file $input" - ocrmypdf --quiet --jobs $(nproc) --language deu $input $output \ - || errlog "could not add ocr on $input" \ - || return $? - - [ ! -f $output ] && return 0 - - mv $output $input \ - || errlog "could not rename $output to $input" \ - || return $? - optimize $input \ - || return $? -} - createonepdf() { local output=$1 -- 2.47.3