在浏览器中打开PDF文件,而不是下载pdf文件 [英] Open PDF file in browser rather than downloading pdf file

查看:711
本文介绍了在浏览器中打开PDF文件,而不是下载pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想允许用户打开或保存PDF文件,而不是PDF文件自动下载。

I want to allow user to open or save PDF file rather than PDF file downloads it automatically.

让我们说一个简单的锚标签

Let us say i have a simple anchor tag

< a href =pdf / pdf-file1.pdf>查看PDF< / a>

我尝试使用下载 type =application / pdf在自己的锚点,但它不工作。

I tried to use download as well as type="application/pdf" in the anchor it self but it does not work.

我可以强制PDF文件打开使用C#代码后面的文件,但我想避免那里有一个简单的HTML的方式做,甚至在HTML 5

I can force PDF file to open using C# code behind file, but I want to avoid that is there a simple HTML based way of doing it, not even in HTML 5

推荐答案

你自己托管这个pdf吗?如果是,请尝试向锚标签添加 target =_ blank

Are you hosting this pdf yourself? If so, try adding target="_blank" to the anchor tag:

<a href="pdf/pdf-file1.pdf" target="_blank"> View PDF </a>

否则,尝试一下iframe:

Otherwise, try an iframe:

<iframe src="pdf/pdf-file1.pdf" 
style="width:600px; height:800px;" frameborder="0"></iframe>

此外,如果您从自己的后端发送此文件,将Content-Disposition设置为inline您的回应:

Also, if you're sending this file from your own backend set the Content-Disposition to inline in your response:

Content-Type: application/pdf
Content-Disposition: inline; filename="pdf-file1.pdf"

这篇关于在浏览器中打开PDF文件,而不是下载pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆