Skip to content

Instantly share code, notes, and snippets.

@dgrant
Created April 27, 2015 01:11
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 dgrant/7c2e3c536307f6d5b457 to your computer and use it in GitHub Desktop.
Save dgrant/7c2e3c536307f6d5b457 to your computer and use it in GitHub Desktop.
Script to convert *.ps files to *.pdf and *.eps files for inclusion in Latex documents
#!/bin/sh
#Script to convert *.ps files to *.pdf and *.eps files for inclusion in Latex documents
ONE=1
FOUND=0
numberEPS=0
numberPDF=0
for file #Traverse all files in directory.
do
echo "$file" | grep -q "\.\ps" # Check whether filename contains .ps
if [ $? -eq $FOUND ]; then
fname=$file # Strip off path.
epsn=`echo $fname | sed -e "s/\(.*\.\)ps/\1eps/g"` # Substitute .ps for .eps
pdfn=`echo $fname | sed -e "s/\(.*\.\)ps/\1pdf/g"` # Substitute .ps for .pdf
pngn=`echo $fname | sed -e "s/\(.*\.\)ps/\1png/g"` # Substitute .ps for .png
if [ $file -nt $epsn ]; then
echo Converting $file to $epsn;
ps2epsi $file $epsn;
let "numberEPS += 1"
fi
if [ $file -nt $pdfn ]; then
echo Converting $epsn to $pdfn
#convert -rotate 90 $epsn $pdfn
ps2pdf $file $pdfn
mogrify -rotate 90 $pdfn
let "numberPDF += 1"
fi
if [ $file -nt $pngn ]; then
echo Converting $epsn to $pngn
convert -rotate 90 -quality 100 $epsn $pngn
fi
fi
done
if [ "$numberEPS" -eq "$ONE" ]; then
echo "$numberEPS EPS file converted."
else
echo "$numberEPS EPS files converted."
fi
if [ "$numberPDF" -eq "$ONE" ]; then
echo "$numberPDF PDF file converterd."
else
echo "$numberPDF PDF files converted."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment