1

My Firefox and Chrome usually open PDF files very nicely, without asking and within the browser window.

When clicking on a link to a PDF on our own website:

  • Firefox asks if it should download them, to see it I need to open the download history.
  • Chrome downloads it automatically, but here as well, opening the PDF needs an extra click.

If I copy the PDF to a different Server (Django installation with lighttpd), Firefox and Chrome will display it nicely as usual.

What's wrong?

  • You might want to add your sent headers. This is just guessing. Also, this belongs on stackoverflow.com, not here :) – Martijn Jul 10 '15 at 9:40
  • 2
    I'm not migrating this to StackOverflow, it looks appropriate here. It isn't necessarily a coding question, but it is certainly a webmaster question. – Stephen Ostermiller Jul 10 '15 at 10:19
  • I think you don't need to convert in your inputStream to charset=UTF-8" for PDF – Gopal Singh Jun 14 '18 at 11:31
  • I'm voting to close this question as off-topic because it was due to misconfiguration of the server. – Rob Jun 14 '18 at 11:52
  • This looks to be off-topic because it requires us to guess what could be wrong. There's nothing tangible for us to work with. – John Conde Jun 14 '18 at 15:22
3

See How to force files to open in browser instead of download (pdf)? which has an answer from ColinM that tells you exactly what the headers should be:

To indicate to the browser that the file should be viewed in the browser:

Content-Type: application/pdf
Content-Disposition: inline; filename="filename.pdf"

To have the file downloaded rather than viewed:

Content-Type: application/pdf
Content-Disposition: attachment; filename="filename.pdf"

EDIT: The quotes around the filename are required if the filename contains special characters such as filename[1].pdf which may otherwise break the browser's ability to handle the response.

  • Thank you for this very nice answer. However, I have to accept my own more special one, because that one solved my problem. – Philipp Zedler Jul 10 '15 at 13:34
0

The solution was rather special.

The server had the default mime-type application/octet-stream for PDF files. After changing this to application/pdf everything worked fine.

In the lighttpd configuration I achieved the change by adding this definition:

mimetype.assign += ( ".pdf" => "application/pdf" )

Not the answer you're looking for? Browse other questions tagged or ask your own question.