Skip to content

Instantly share code, notes, and snippets.

@MartyLake
Created October 9, 2022 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MartyLake/ef8dfb6a66cef0e145944a31c5db4fd6 to your computer and use it in GitHub Desktop.
Save MartyLake/ef8dfb6a66cef0e145944a31c5db4fd6 to your computer and use it in GitHub Desktop.
unpaper example
# 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