I need a shell script to detect valid PDFs. That is, I need to retain only plain ASCII PDFs. Other PDFs which contain non-ASCII contents and malicious scripts need to be deleted. How could I go about doing that? Is there any script available to do it?
What you want is called a virus scanner. Eg. ClamAV
There are a few python scripts here. "The Malware Archives: PDF Files" also Bruce Schneier has mentioned this on his site.
pdf2ps is easy but much less sure. This is interesting PDF/A http://en.wikipedia.org/wiki/PDF/A disallows multimedia elements.