Instead of downloading PDF, how to force PDF to open/view in browser only?

Whenever I upload a PDF, it shows in the topic as follows:

image

I’m using Inline PDF to display it in Desktop version. But, in mobile Inline PDF won’t work. Further, Google or other search engines autodetect the PDF files, but whenever the user clicks on those results, the PDF download dialogue will appear instead of opening in a tab. This is a bit unfriendly and most of the users prefer to view the PDF online instead of downloading it at a place and opening.

Is there any solution to this?

NOTE: I’ve seen this topic PDF preview instead of download, on uploaded files, but the topic ended without any relation to the original question. Hence, this new topic.

7 Likes

Thanks for raising this question. I’m also curious to know the answer!

3 Likes

Embed a PDF Stored on Google Drive

PDFs display in Mobile as well as Desktop.

(My preferred method so PDFs in iFrames display in any device as responsive)

  1. Share
  2. Copy Share Link
  3. Open Share Link in a New Tab
  4. Click the 3 Vertical Dots in the Top Right Corner
  5. Select Embed Item
  6. Copy the Displayed iFrame Code
  7. Paste it in the Discourse Composer / Editor

Desktop Example…

Mobile Example…

2 Likes

Inline PDF does not work for me on desktop either.

I’m partially successful displaying PDFs inline when adding them to FileHelper.inline_images

But then a parameter “inline=1” is needed:

This could be added in some theme-component (Inline PDF Previews).

I would like to learn a clean way to switch discourse to serve PDFs with content-disposition: inline using a plugin or a configuration option.

I managed to write a small plugin for this purpose:

3 Likes