Skip to content

Instantly share code, notes, and snippets.

@rotaliator
Created October 30, 2025 16:18
Show Gist options
  • Select an option

  • Save rotaliator/f3708e804984a0ca006f302da99bb77d to your computer and use it in GitHub Desktop.

Select an option

Save rotaliator/f3708e804984a0ca006f302da99bb77d to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
if [ "$#" -lt 2 ]; then
echo "Usage: $0 input.pdf output.pdf"
exit 1
fi
INPUT_PDF=$1
OUTPUT_PDF=$2
echo "Extracting JPG's from PDF"
pdfimages -all $INPUT_PDF extracted
echo "Cleaning JPG's"
convert extracted-*.jpg -colorspace Gray -normalize -level 20%,80% -brightness-contrast 10x40 -set filename:fn 'clean-%[basename]' '%[filename:fn].jpg'
echo "Creating output PDF..."
convert clean-*.jpg $OUTPUT_PDF
echo "...done"
echo "Cleaning temporary files..."
rm extracted-*.jpg
rm clean-extracted-*.jpg
echo "All done :)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment