-
-
Save marcosrogers/fc0250a52490e92ab8293bd781231a7e to your computer and use it in GitHub Desktop.
Gnome simple-scan post processing script to run OCR with ocrmypdf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # ocr-script.sh | |
| # | |
| # Usage: | |
| # Set this file as the post-processing script in the simple-scan preferences. No extra arguments needed. | |
| # Any postprocessing script arguments entered in the preferences will be passed along to ocrmypdf, for | |
| # example, add -l=eng+spa to recognize English and Spanish text. | |
| # | |
| # Requirements: | |
| # - simple-scan | |
| # - ocrmypdf | |
| # | |
| # For reference, at the time of writing the arguments from simple-scan are: | |
| # $1 - the mime type, eg application/pdf | |
| # $2 - whether or not to keep a copy of the original file | |
| # $3 - the filename | |
| # $4..N - postprocessing script arguments entered in preferences | |
| filename=$3 | |
| keep_original=$2 | |
| if [[ "$keep_original" == "true" ]]; then | |
| ocr_filename="${filename%\.*}.ocr.${filename##*\.}" | |
| extra_msg_details="Saved as ${ocr_filename##*\/}.\nOriginal saved as ${filename##*\/}." | |
| else | |
| extra_msg_details="Saved as ${filename##*\/}." | |
| fi | |
| /usr/bin/ocrmypdf --deskew --clean --force-ocr ${@:4} "$filename" "${ocr_filename-$filename}" &> /tmp/ocr.log | |
| if [ $? -ne 0 ]; then | |
| notify-send -i scanner "OCR Failed" "See /tmp/ocr.log" | |
| exit 1 | |
| fi | |
| notify-send -i scanner "OCR Complete" "$extra_msg_details" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your line 28 is an error if no additional command line parameters are provided. It results in an empty-string parameter which ocrmypdf interprets as the input file name.