add example pdf-to-text script

This commit is contained in:
Malin Freeborn 2022-09-12 23:01:54 +02:00
parent d2746b505d
commit dda08f40e9
Signed by: andonome
GPG Key ID: 52295D2377F4D70F
2 changed files with 26 additions and 0 deletions

View File

@ -18,3 +18,4 @@ Arch: tesseract-data-eng and poppler-utils
> tesseract -l eng "$x" - >> *out*.txt
> done
- [Example script](data/pdf-to-txt.sh)

25
data/pdf-to-txt.sh Executable file
View File

@ -0,0 +1,25 @@
#!/bin/bash
pdftoppm -png input.pdf page
for x in *png; do
tesseract -l eng "$x" - >> out.tex
done
rm *png
sed -i -ze :a -e 's/\([a-z]\)\(-\)\n\+\([a-zA-Z]\)/\1\3/g' out.tex
sed -i -ze :a -e 's/\([a-z]\)\n\+\([a-zA-Z]\)/\1 \2/g' out.tex
sed -i -ze :a -e 's/\([A-Z]\){3}\+\n/\1 XYZ/g' out.tex
sed -i -ze :a -e 's/\n\([A-Z]\{3\}\+\)\n/\\section{\1}\n/g' out.tex
sed -i -ze :a -e 's/\([a-z]\)\. \([A-Z]\)/\1\.\n\2/g' out.tex
sed -i 's/“//g' out.tex
sed -i "s/”/''/g" out.tex
sed -i "s//'/g" out.tex
sed -i "s//'/g" out.tex
sed -i "s/\.''/''\./g" out.tex
sed -i "s/ — / -- /g" out.tex
sed -i 's/\$/\\$/g' out.tex
sed -i 's/%/\\%/g' out.tex
sed -i 's/&/\\&/g' out.tex