There are various tools out there that do things like this. One way is to convert the file to postscript, and then use ghostscript (short gs), the postscript swiss army chain saw. (Maybe it can even handle the PDF directly, I haven't tried that for quite some time).