Skip to content

Instantly share code, notes, and snippets.

@venam
Created November 25, 2015 17:28
Show Gist options
  • Save venam/114a325184cc6a17ed93 to your computer and use it in GitHub Desktop.
Save venam/114a325184cc6a17ed93 to your computer and use it in GitHub Desktop.
convert a list of pdfs to images of good quality
#!/bin/bash
if [ "$#" -lt 1 ]; then
echo "Usage: $0 pdfs" >&2
exit 1
fi
for pdf in "$@"
do
echo "Converting $pdf to images"
pages="$( pdfinfo "$pdf" |grep Pages | sed -e 's/Pages:\( \)\+//')"
dir="$( echo $pdf | sed -e 's/.pdf//')"
if [ -d $dir ]; then
echo "directory $dir already exists"
else
mkdir $dir
convert -density 150 "$pdf[0-$pages]" -quality 90 "$dir/page-%d.jpg"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment