logo

Kleurenschema: blauw - grijs


Content-Disposition Problem with Adobe PDF plugin for Firefox

Update 2010-06-13: Using the latest software: FF 3.6.3 fully updated, Windows 7 fully updated, I could no longer reproduce the bug I described earlier. Whether or not the Adobe PDF plugin was enabled did not affect the behaviour.

Bug tracking: https://bugzilla.mozilla.org/show_bug.cgi?id=428771

Summary: Firefox with the Adobe PDF plugin enabled does not offer to download a PDF but always opens the PDF, even when the server sends a content-disposition: attachment HTTP header. Firefox then blanks the current webpage, so you have to hit the back button to return to the original page. This does not happen to Firefox when the plugin is disabled. Internet Explorer and Google Chrome are not affected.

Evert Mouw, 2010-01-14
post@evert.net | www.animamundi.eu

Test Results using Firefox

My website at http://www.animamundi.eu/index.php?c=hobbies&p=klapdeuren

Clicking on the link klapdeuren.pdf with the Adobe PDF plugin enabled results in Adobe Reader starting up and opening the file. Note that Adobe Reader says that I am opening plugin-klapdeuren.pdf

After closing Adobe Reader, this is what I get:

And that is really sad. I know I have to hit the back button, but I really would prefer to see the correct webpage.

Additional testing

The HTTP header response from the server is correct:

root@bifrost:/# wget -S http://www.animamundi.eu/content/actief/klapdeuren/klapdeuren.pdf
--2010-01-14 20:49:15--  http://www.animamundi.eu/content/actief/klapdeuren/klapdeuren.pdf
Resolving www.animamundi.eu... 127.0.1.1
Connecting to www.animamundi.eu|127.0.1.1|:80... connected.
HTTP request sent, awaiting response...
  HTTP/1.1 200 OK
  Date: Thu, 14 Jan 2010 19:49:15 GMT
  Server: Apache/2.2.12 (Ubuntu)
  Last-Modified: Mon, 17 Apr 2006 19:23:27 GMT
  ETag: "25612-a253-411a55b5de9c0"
  Accept-Ranges: bytes
  Content-Length: 41555
  content-disposition: attachment; filename="klapdeuren.pdf"
  content-type: application/pdf
  content-description: PDF download
  Keep-Alive: timeout=15, max=100
  Connection: Keep-Alive
Length: 41555 (41K) [application/pdf]
Saving to: `klapdeuren.pdf'

100%[=====(...)====>] 41,555      --.-K/s   in 0s

2010-01-14 20:49:15 (206 MB/s) - `klapdeuren.pdf' saved [41555/41555]

Client Environment

Operating system: Windows 7 Professional (Dutch) build 7600

Firefox

Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6 GTB6



Internet Explorer



Google Chrome version:

Adobe Reader

Server Environment

Apache/2.2.12 (Ubuntu)
Ubuntu Server 9.10 (32-bits)
Linux bifrost 2.6.31-17-generic-pae #54-Ubuntu SMP Thu Dec 10 17:23:29 UTC 2009 i686 GNU/Linux

.htaccess file:
<IfModule mod_headers.c>
  <FilesMatch "\.(?i:pdf)$">
    setEnvIf REQUEST_URI "/([^/]+)$" filename=$1
    header set content-disposition "attachment; filename=\"%{filename}e\"" env=filename
    header set content-type "application/pdf"
    header set content-description "PDF download"
  </FilesMatch>
</IfModule>

Workaround

For another page on my website, I have created a workaround using PHP. The webpage is located at http://www.animamundi.eu/index.php?c=computer&p=mailserver+en+spam. I use an URL like download?file=eigen_mailserver.pdf and the PHP script sets the correct headers. The source code for the PHP script download.php is:

<?php
// force browser to download a pdf instead of opening it
// evert mouw, 2010-01-14

// get filename
if (isset ($_GET['file'])) {
     
$file $_GET['file'];
     if (
$file=='') {
         
$file="(empty)";
     }
}
else {
    
$file="(empty)";
}

if ( 
stripos($file,"pdf") ) {
    if (
file_exists($file) ) {
        
header('Content-Description: PDF download');
        
header('Content-type: application/pdf');
        
header('Content-Disposition: attachment; filename="'.basename($file).'"');
        
header('Content-Length: ' filesize($file));
        
flush();
        
readfile($file);
    }
    else {
        echo 
"$file not found";
    }
}
else {
    echo 
"$file is not a PDF";
}
?>