There are several tools exists for this kind of job:
- http://www.willus.com/k2pdfopt/
- http://code.google.com/p/papercrop/
- http://briss.sourceforge.net/
- https://sites.google.com/site/pdfscissors/
I'd check them out before trying to reinvent the wheel. Or you had not meant programming a new solution but then your question is off topic on this site, see the FAQ.