如何强制PDF在浏览器中打开/查看,而不是下载PDF?

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 个赞

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

3 个赞

嵌入存储在 Google 云端硬盘中的 PDF

PDF 可在移动设备和桌面设备上显示。

(我偏爱的方法,以便 iFrame 中的 PDF 在任何设备上都能以响应式方式显示)

  1. 共享
  2. 复制共享链接
  3. 在新标签页中打开共享链接
  4. 点击右上角的三个垂直点
  5. 选择“嵌入项目”
  6. 复制显示的 iFrame 代码
  7. 将其粘贴到 Discourse 的撰写器/编辑器中

桌面示例…

移动设备示例…

2 个赞

内联 PDF 在桌面端对我来说也不起作用。

我部分成功地在添加 PDF 到 FileHelper.inline_images 时内联显示它们

但随后需要一个参数“inline=1”:

这可以在某个主题组件中添加(https://meta.discourse.org/t/inline-pdf-previews/157649)。

我想学习一种干净的方法,使用插件或配置选项将 Discourse 切换为使用 content-disposition: inline 来提供 PDF。

我写了一个小程序来实现这个目的:

4 个赞