Last active
November 20, 2018 03:30
-
-
Save coolreader18/0f89a8e6088c080b9f5007602e8aec0d to your computer and use it in GitHub Desktop.
A script to OCR a pdf file
This file contains 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
#!/usr/bin/env sh | |
set -e | |
if [ ! -f "$1" ]; then | |
echo "Input file doesn't exist" | |
exit 1 | |
fi | |
if [ ! "$2" ]; then | |
echo "Must provide output file" | |
exit 1 | |
fi | |
input="$(realpath "$1")" | |
output="$(realpath "$2")" | |
shift 2 | |
tmpdir="$(mktemp -d)" | |
cd "$tmpdir" | |
cleanup() { | |
cd / | |
rm -rf "$tmpdir" | |
} | |
trap cleanup 2 | |
pdftoppm "$input" img -png | |
find . -name 'img-*.png' | sort >fileslist | |
ln -s "$output" out.pdf | |
touch out.pdf | |
tesseract fileslist out $@ pdf | |
cleanup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment