问题描述
我想允许用户打开或保存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文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!