我想允许用户打开或保存 PDF 文件而不是自动下载 PDF 文件。
假设我有一个简单的 anchor 标签
<a href="pdf/pdf-file1.pdf" > View PDF </a>
我尝试使用 download
以及type="application/pdf"
在它自己的 anchor 中,但它不起作用。
我可以使用文件隐藏的 C# 代码强制打开 PDF 文件,但我想避免使用基于 HTML 的简单方法来打开它,即使在 HTML 5 中也不行
最佳答案
您自己托管此 pdf 文件吗?如果是这样,请尝试将 target="_blank"
添加到 anchor 标记:
<a href="pdf/pdf-file1.pdf" target="_blank"> View PDF </a>
否则,试试 iframe:
<iframe src="pdf/pdf-file1.pdf"
style="width:600px; height:800px;" frameborder="0"></iframe>
此外,如果您从自己的后端发送此文件,请在您的响应中将 Content-Disposition 设置为内联:
Content-Type: application/pdf
Content-Disposition: inline; filename="pdf-file1.pdf"
关于c# - 在浏览器中打开 PDF 文件而不是下载 pdf 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37236063/