Skip to content

Instantly share code, notes, and snippets.

@epcim
Created October 20, 2015 09:48
Show Gist options
  • Save epcim/177b4a295886979eb596 to your computer and use it in GitHub Desktop.
Save epcim/177b4a295886979eb596 to your computer and use it in GitHub Desktop.

convert PDF to PNG

#!/bin/bash

for i in *.[Pp][Dd][Ff]; do
  NEWNAME=`echo $i | sed 's/.[Pp][Dd][Ff]/.pdf/'`
  mv "$i" "$NEWNAME" 2> /dev/null
done

CNT=0
TOTAL_PDF=`ls -l *.pdf 2> /dev/null | wc -l` 

if [ $TOTAL_PDF -eq 0 ]; then echo "No PDF files found."; exit; fi

for i in *.pdf; do
  ((CNT++))
  FILENAME=`echo $i | sed 's/.pdf$//'`
  printf "\E[33m$CNT\E[0m/\E[33m$TOTAL_PDF\E[0m > Converting \E[36m$i\E[0m \tto \E[36m$FILENAME.png\E[0m... "
  [[ -f "$FILENAME.png" ]] && continue
  convert -density 196 "$FILENAME.pdf" "$FILENAME.png"
  printf "done.\n"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment