Macos – A way to force Firefox to open a file in its Pdf viewer

firefoxfirefox-extensionsmacospdfpdf-reader

I'm trying to view a Pdf file that I found online.

Normally, when I attempt to open a Pdf file, Firefox displays it in its default Pdf viewer (called pdfjs, I believe). This is good and normal behavior.

However
with this specific Pdf that I found online, I click the link to its location, and Firefox brings up the download dialog. It describes the file as a "binary file", even though the file is a Pdf that I can download and view natively.

I'm assuming the web-server is "not telling" Firefox that this Pdf file is, in fact, a Pdf file. So Firefox can only assume that it is a "binary file".

          This spurred me to wonder the question…

If I were to ever encounter this annoyance again, instead of downloading the file, can I force Firefox to open a file (online or otherwise) in its default Pdf viewer?

Attempted Solutions:

  1. I tried the answer from How to call firefox built-in pdf viewer (pdf.js) manually?, but to no avail. Firefox just attempts to download the "binary file".
  2. I added view-source: to the beginning of the Pdf's location (i.e. view-source:https://www.website.com/pdf.pdf), I just get the raw ASCII text displayed of the Pdf file.

PS: I'm using Firefox 48.0.2 …
Yes, it's old….


As requested:

Screenshot of Response and Request Headers

Best Answer

There are several ways that sites can force your browser to download a file instead of opening it directly:

The download HTML Attribute

This attribute on an anchor tag will attempt to force your browser to download the file instead of processing it in the way it normally would.

Generally this is used when you need to take an automatically generated document name and present it as something nice for the user.

Usage: <a href="http://www.website.com/path/to/YourDocument.pdf" download="YourDocument.pdf">...

I have not yet found a way to work around this, but since the real cause of your problem lies below, I haven't researched it entirely...

HTTP Headers

Content-Disposition

A webserver can respond to a request for a document with the Content-Disposition header to describe how the browser should receive the file.

Content-Disposition: Attachment will tell the browser that it should download the file, rather than process it as it normally would.

Content-Disposition: Inline will tell the browser that it can be displayed inside the webpage, or as the webpage.

Here is a Firefox addon that will take Attachment headers and replace them with Inline headers:

https://addons.mozilla.org/en-US/firefox/addon/bypass-forced-download/

Technically, it intercepts Content-Disposition: attachment Headers and rewrites them on the fly to Content-Disposition: inline. It also allows you to specify websites that should and should-not use this rewrite.

As with most addons, your mileage may vary.

Content-Type

A webserver can respond to a request for a document with the Content-Type header to describe the type of document it is returning to the browser.

Content-Type: application/octet-stream is defined as "arbitrary binary data" and is basically only downloadable as a file, the browser won't know what to do with it otherwise.

This is what you see when your browser requests the PDF file you are attempting to view.

Content-Type: application/pdf is what you would probably need if you wanted to view this file in your browser, or at least have Firefox understand what the file is and how to handle it correctly.

Here is a Firefox addon that can be set to listen for, and rewrite Content-Type headers based on their content.

Note: Modifying how your browser handles MIME types can be dangerous.

https://addons.mozilla.org/en-US/firefox/addon/content-type-fixer/

Again, this addon may or may not work in all cases.

Related Question