Force PDFs to download/open in new window?
facelikebambi - April 3, 2008 - 11:56
Hi
I have many nodes with PDF attachments, which automatically open in Acrobat Reader when clicked. It would be really nice to make them open in a new window, or offer the 'Save file' dialogue instead. Otherwise, users can get engrossed in the PDF and not return to my site...
I'm just using the core Upload module, and External Links. External Links handles all normal URL links fine, but doesn't touch attachments.
Any thoughts welcomed - thanks! :)

Take a look at
Take a look at modules/upload/upload.module
/*** Implementation of hook_file_download().
*/
function upload_file_download($file) {
It returns a header in an array, if you add "Content-Disposition: attachment" to that list, then your pdf will open for download rather than in the current window. You'd need to check the mimetype to explicitly set that behaviour for pdfs though (you do have access to $file->filemime within that function so it's not a problem). If you've only got pdfs as attachments then just change it anyway.
I know it's not ideal to change a core function, but as long as you remember to make the change again if you upgrade Drupal then everything will be fine ;o)
Pobster
That's great - thanks!
That's great - thanks!
PDF's does not open/download in the different page
I have write the code in the core upload module as you have suggested but that does not work for me.
I am using Drupal 6 installation. please suggest me how could i do it.