html - 需要关闭 pdf 查看器工具栏
问题描述
试图查看 pdf 文件。工具栏在不同浏览器中的显示方式不同。有没有办法在所有浏览器中隐藏这个工具栏。
.cshtml 文件中的代码:
<div id="zoomOut">
<object data="@Url.Action("ViewFinalReport", new { Id = @ViewBag.FileName, SystemId = Model.SystemId, InspectionReportId = Model.ReportId })" type="application/pdf" width="900" height="650">
</object>
</div>
控制器中的代码:
public FilePathResult ViewFinalReport(string Id, int SystemId, int InspectionReportId)
{
string path = "";
string filePath = "";
string customerFolderName = "";
SystemInspectionReport SystemInspectionReport = new Models.Objects.SystemInspectionReport();
TestSoln.Models.Objects.SystemInspectionReports SystemInspectionReports = new Models.Objects.SystemInspectionReports(SystemInspectionReport, new BaseParams() { customerId = CustomerId, userId = UserId, timeOffSet = TimeOffSet });
string FileName = SystemInspectionReports.GetInspectionSystemReportFileName(SystemId, InspectionReportId, true);
DataTable dataTable = GetCustomerDetails(CustomerId).Tables[0];
if (dataTable.Rows[0]["Folder"] != DBNull.Value)
{
customerFolderName = dataTable.Rows[0]["Folder"].ToString();
}
path = HttpContext.Application["FileFolder"].ToString() + "\\" + customerFolderName + "\\InspectionReports\\" + SystemId + "\\" + InspectionReportId + "\\FinalReport\\" + FileName;
filePath = new AppSettings()[AppSettingsKey.FileLocation].Value + path;
return File(filePath, "application/pdf");
}
我可以在所有浏览器中查看 pdf。但问题是工具栏在不同浏览器中的显示方式不同。所以我想隐藏工具栏。任何想法??
解决方案
您可以使用embed
而不是在 url 的末尾object
添加来删除工具栏。#toolbar=0
不确定这是否同样适用于对象。
<embed src="@Url.Action("ViewFinalReport", new { ...})#toolbar=0" width="500" height="375"> (Disable toolbar)
<embed src="@Url.Action("ViewFinalReport", new { ...}#toolbar=1" width="500" height="375"> (Enable toolbar)
编辑:
目前没有可以完成并适用于所有浏览器的简单配置。
之后设置的#toolbar
其他一些参数#
是Adobe 专有的“ PDF Open Parameters ”。这适用于 Chrome,因为 Chrome 的 PDF 查看器与 Acrobat 的参数兼容。
因此,如果您的用户不使用 Adobe 阅读器扩展,大多数用户使用默认浏览器配置,则此参数可能不起作用。作为开发人员,我们无法控制用户在浏览器上配置了哪些插件/扩展来显示 PDF 文件。
另一种方法是使用 Mozilla 的 pdf.js 库,它可以在画布内呈现 pdf 文件。在此链接中,您将找到一些实时示例:https ://mozilla.github.io/pdf.js/examples/
这是一个常见问题,您可以在 Stack Overflow 和 mozilla 社区上找到一些关于它的问题:
如何在网页中嵌入 PDF 而不显示 Firefox PDF 查看器工具栏?
在浏览器中显示 PDF 时可以隐藏 Adobe 浮动工具栏吗?
隐藏使用 firefox 在 iframe 中打开的 pdf 文件的工具栏(这个也有很好的解释)
推荐阅读
- mysql - 将行复制到另一个表但有条件
- javascript - JavaScript 提交按钮在以编程方式触发时返回 isTrusted true
- node.js - 如何将我的数据发布到 mongodb 数据库
- audiokit - 使用 AKSampler 以特定音序器速度静音音符
- r - 根据条的大小更改条的颜色 R
- python - 芹菜、Django 和@shared_task
- node.js - 我的 fs.writeFile 不会将任何内容记录到我的 JSON 文件中?
- django-views - SMTPSenderRefused at /appointment
- javascript - 获取客户端操作系统、操作系统版本、计算机名称、mac id 和设备 id
- graphql - Apollo 客户端的代码生成器在我的类型中添加了不需要的“或 null”