Sitecore's MediaRequestHandler
can be customized so that you can do something server side whenever a media request occurs.
You haven't said exactly what action you want to take so I can't be more specific, but these links should show you how to manipulate the media request handler:
- Sitecore serves media items even with incorrect extensions
- Handling Duplicate Media Paths in Sitecore.
If you really need to fire javascript you could ensure that all requests for PDF's get diverted to a specific webpage witch contains the JS on it. You would then need to redirect to the actual PDF item. This would be achieved with the MediaRequestHandler as mentioned above.
I realise this is really messy, but without more detail about what you need to achieve I can't think of a better solution.