Created
October 9, 2022 22:54
-
-
Save MartyLake/ef8dfb6a66cef0e145944a31c5db4fd6 to your computer and use it in GitHub Desktop.
unpaper example
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
# folder repository | |
# ./ #<-- destination folder | |
# ./originals/any.pdf #<-- any number of pdfs to convert, originals | |
# ./originals/unpaper.sh #<-- this script | |
# inspired from https://gist.github.com/legumbre/1182280/60c3bfc13b9d89b57fef733f67ad60de2624be6a | |
set -x | |
for i in *.pdf; do | |
gs -q -dNOPAUSE -dBATCH -sDEVICE=ppmraw -sOutputFile=%04d.ppm "$i" | |
for f in *.ppm; do | |
# adjust brightness (20) and contrast (10) to preprocess for unpaper | |
convert "$f" -brightness-contrast 20x10 -colorspace Gray -grayscale average "${f%.ppm}.bright.ppm" | |
done | |
unpaper --layout single %04d.bright.ppm unpaper%04d.ppm | |
echo you may need to rm ../"$i" | |
convert unpaper*.ppm ../"$i" | |
open output.pdf | |
echo 'you may want to clean with rm *.ppm' | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment