10

When clicking a PDF link in Firefox and Chrome, the file will sometimes be opened for in-browser viewing and sometimes prompt a "Save as" dialog.

If I wanted to force the link to always prompt a download I could use the download HTML5 attribute.

However, I want to do the opposite. I.e., force the links to always be viewed in the browser.

Sort of an inverse download attribute. Is there such a thing? :)

I'd prefer to not modify response headers when serving PDF documents - I want to be able to specify in markup what the browser behavior should be.

Thanks!

Ted Nyberg
  • 7,001
  • 7
  • 41
  • 72
  • 3
    possible duplicate of [How to force PDF files to open in browser?](http://stackoverflow.com/questions/6293893/how-to-force-pdf-files-to-open-in-browser) – Diodeus - James MacFarlane Oct 08 '13 at 20:06
  • My guess is "in browser" viewing is only available through some kind of plug-in. In that case, my recommendation is to ditch PDF altogether and deliver the content using HTML5. – beautifulcoder Oct 08 '13 at 20:08
  • Weird thing is that **some** PDF files are opened for viewing in the browser, others prompt a download. The question posted as a possible duplicate doesn't contain any relevant answers since I don't want to append/modify headers. The files are hosted on Amazon S3 and I don't want my app to download them, change the headers and then serve them to the client. :/ – Ted Nyberg Oct 09 '13 at 11:17
  • http://stackoverflow.com/questions/1395151/content-dispositionwhat-are-the-differences-between-inline-and-attachment – adt Mar 13 '15 at 22:18

3 Answers3

1

You can achieve that by setting the appropriate header (for instance, in case of PDF, the header will be Content-type: application/pdf;

With this header, the browser will know the mime-type of the file and display it if it is compatible with it.

Here you can see the headers for a PDF.
As a hint, what I like to do is to use some sort of controller (in case you are using a backend language) that handles the download. Hence, to download myNewProject.pdf I do

<a href='download.php?file=myNewProject.pdf&viewInBrowser=1'>Download!</a>

Then I can set the appropriate headers depending on the file type, or if I want to force download or view it in the browser...

Nico
  • 790
  • 1
  • 8
  • 20
  • 2
    This does not mention the use of `attached`, see older post with similar question here: http://stackoverflow.com/questions/6293893/how-to-force-files-to-open-in-browser-instead-of-download-pdf – Christophe Roussy Feb 04 '15 at 15:13
-2

I'm using Firefox in XP. I went to the OPTIONS under Tools and found Portable Document Format. Click on it and it will allow you to change the way PDF files are handled.

Bob
  • 7
  • 4
    The OP was not asking as a browser user, but as a content provider. He wants people using his site to not download the PDF file, so I'm afraid this will not help him. – kdopen Mar 13 '15 at 22:06
-13

open the file in a Microsoft Word and save as html.

Yash
  • 1
  • 3
  • 1
    I think you misunderstood. I want PDF links on **my site** to always be opened for viewing in the visitor's browser as opposed to prompting a download. – Ted Nyberg Oct 09 '13 at 11:17