Skip to content

Instantly share code, notes, and snippets.

@blairanderson
Forked from dvcama/fromPdfToJpg
Created July 16, 2018 20:08
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 blairanderson/a5ba953f10eb30fd79e264c1c2047646 to your computer and use it in GitHub Desktop.
Save blairanderson/a5ba953f10eb30fd79e264c1c2047646 to your computer and use it in GitHub Desktop.
bash: extract high-res images from pdf using imagemagick (recursively)
#!/bin/bash
# extract jpg from PDF
# based on a script edited by Purch
#####################################
if [ -z $1 ];then echo Give target directory; exit 0;fi
find "$1" -depth -name '*.pdf' | while read file ; do
directory=$(dirname "$file")
oldfilename=$(basename "$file")
newfilename=$(echo "$oldfilename" | sed 's/.pdf/.jpg/g')
if [ "$oldfilename" != "$newfilename" ]; then
convert -density 600x600 "$directory/$oldfilename" "$directory/$newfilename"
echo ""$directory/$oldfilename" ---> "$directory/$newfilename""
mv -i "$directory/$oldfilename" "$directory/$oldfilename.done"
#echo
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment