Open PDF file in new window D7

Public

add this to template.php and update the THEMENAME

Get raw version
php
  1. function THEMENAME_file_link($variables) {
  2. $file = $variables['file'];
  3. $icon_directory = $variables['icon_directory'];
  4.  
  5. $url = file_create_url($file->uri);
  6. $icon = theme('file_icon', array('file' => $file, 'icon_directory' => $icon_directory));
  7.  
  8. // Set options as per anchor format described at
  9. // http://microformats.org/wiki/file-format-examples
  10. $options = array(
  11. 'attributes' => array(
  12. 'type' => $file->filemime . '; length=' . $file->filesize,
  13. ),
  14. );
  15.  
  16. // Use the description as the link text if available.
  17. if (empty($file->description)) {
  18. $link_text = $file->filename;
  19. }
  20. else {
  21. $link_text = $file->description;
  22. $options['attributes']['title'] = check_plain($file->filename);
  23. }
  24.  
  25. //open files of particular mime types in new window
  26. $new_window_mimetypes = array('application/pdf','text/plain');
  27. if (in_array($file->filemime, $new_window_mimetypes)) {
  28. $options['attributes']['target'] = '_blank';
  29. }
  30.  
  31. return '<span class="file">' . $icon . ' ' . l($link_text, $url, $options) . '</span>';
  32. }