PDF is shown as binary text in browser instead of being downloaded

5,750

Why is this and how can I download this PDF file?

The website is broken and is not serving PDF files correctly. Contact [email protected].

Using the Firefox developer tools (press f12, select "Net", then select "All" we can see the response and request headers:

enter image description here

Content-Disposition inline;filename=U1a.pdf

The above tells the browser to serve the page content inline:

In a regular HTTP response, the Content-Disposition response header is a header indicating if the content is expected to be displayed inline in the browser, that is, as a Web page or as part of a Web page, or as an attachment, that is downloaded and saved locally.

You can open the PDF by saving the page locally and opening the PDF:

  1. Right click on the page and select "Save as" (or press ctrls)

    enter image description here

  2. Choose a directory and click "Save".

  3. Navigate to the chosen directory in Explorer.

  4. Double click U1a.pdf.

Share:
5,750

Related videos on Youtube

user1580348
Author by

user1580348

Updated on September 18, 2022

Comments

  • user1580348
    user1580348 over 1 year

    In Chrome, when I enter a URL to a PDF file, usually the browser's Save dialog opens to save the PDF file to my hard disk, for example:

    http://www.pdf995.com/samples/pdf.pdf

    Now I have found a PDF URL where this, unfortunately, does not work:

    https://formulare.bmf.gv.at/service/formulare/inter-Steuern/pdfd/2015/U1a.pdf

    With this PDF URL, no Save dialog is opened and the binary text of this PDF is shown in the browser:

    enter image description here

    Why is this and how can I make it download automatically when I click the URL?

    OS: Windows 7 x64 SP1

  • DavidPostill
    DavidPostill over 7 years
    Did you actually try this? It doesn't work. The website is not serving PDF files correctly. See my answer.
  • user1580348
    user1580348 over 7 years
    Thank you. But I don't want to view the PDF in the browser, I just want to download the PDF when I click on the URL.
  • user1580348
    user1580348 over 7 years
    Thank you. How is the website not serving PDF files correctly? Can you please explain the technical details?
  • DavidPostill
    DavidPostill over 7 years
    @user1580348 There are many different possibilities ...
  • user1580348
    user1580348 over 7 years
    Strange: When I enter the PDF URL https://formulare.bmf.gv.at/service/formulare/inter-Steuern/‌​pdfd/2015/U1a.pdf in Firefox, the PDF is displayed correctly as PDF in Firefox (without downloading).
  • user1580348
    user1580348 over 7 years
    For example? Can you name some, please?
  • DavidPostill
    DavidPostill over 7 years
    @user1580348 The most likely is that the web server is serving the wrong mime type for pdf files and is serving it as html. See Properly Configuring Server MIME Types
  • Devidas
    Devidas over 7 years
    Ok sorry I missunderstood. and did not read your question thoroughly.
  • user1580348
    user1580348 over 7 years
    I have now activated Chrome PDF Viewer in chrome://plugins, but Chrome still displays the PDF as binary text. So why this (displaying the PDF in the browser) is working in Firefox and not in Chrome?
  • Devidas
    Devidas over 7 years
    but to my surprise it did open in Mozilla and not in chrome very strange behavior I agree to your point.
  • Devidas
    Devidas over 7 years
    this can be bug in either web server or chrome. More probable it is chrome bug as it opens in Mozilla
  • user1580348
    user1580348 over 7 years
    Also in Internet Explorer the PDF is displayed correctly as PDF (no download).
  • user1580348
    user1580348 over 7 years
    In Opera there is a strange security warning: It says that it is not possible to complete the secure transaction! ???
  • user1580348
    user1580348 over 7 years
    IMO, this cannot be, as Firefox shows a correct MIME type for the PDF URL: http://i.imgur.com/iPoybDn.png (application/pdf).
  • DavidPostill
    DavidPostill over 7 years
    @user1580348 It fails in Firefox in the same way for me. But works in IE. Strange.
  • John Keates
    John Keates over 7 years
    Might be a attachment status header set to inline
  • DavidPostill
    DavidPostill over 7 years
    @JohnKeates You got it Content-Disposition inline;filename=U1a.pdf
  • DavidPostill
    DavidPostill over 7 years
    @user1580348 Answer updated.
  • user1580348
    user1580348 over 7 years
    Thank you very much for the information! So does this indicate that it's the server's fault or it's Chrome's fault?
  • user1580348
    user1580348 over 7 years
    Or more precisely: Is it the server's fault or is there an error in the website's HTML code containing the link to this PDF file?
  • DavidPostill
    DavidPostill over 7 years
    @user1580348 Content-Disposition inline;filename=U1a.pdf is the response from the server, so it is the server that is misconfigured.
  • user1580348
    user1580348 over 7 years
    I needed to know whom I should blame: The server admin or the website developer. BTW, how could the server admin fix this? Thank you! (I am not maintaining the site; it's just for curiosity).
  • DavidPostill
    DavidPostill over 7 years
    @user1580348 I would ask both of them. It depends where they have decided to split their responsibilities ...