Converting PDF to EPS on entire directory

We recently had a paper accepted to a journal, and they required that all figures be submitted in EPS format. I normally export all of my figures from Matplotlib in PDF, so I had to figure out a way to convert them. I got good results using the "pdftops -eps file.pdf" command in Ubuntu. The only problem was that I had to do it for a whole directory of figures, and when I tried "pdftops -eps *.pdf" it choked.

Python to the rescue. Here's a simple python script that will grab all PDFs in the current directory (wherever the script is placed), and automatically convert them to nice EPS files.

from glob import *
from os import system
fileList = glob('*.pdf')
for f in fileList:
  system('pdftops -eps {0}'.format(f))

So easy! I love python. The glob command grabs all the names of files that match the patten you want. In this case "*.pdf" returns a python list of all files with PDF extension. Then, it just iterates through the filenames, inserting each filename into a system command using the string format function. DONE!