首页 > 解决方案 > 需要关闭 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。但问题是工具栏在不同浏览器中的显示方式不同。所以我想隐藏工具栏。任何想法??

标签: htmlasp.netasp.net-mvcc#-4.0

解决方案


您可以使用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其他一些参数#Adob​​e 专有的“ PDF Open Parameters ”。这适用于 Chrome,因为 Chrome 的 PDF 查看器与 Acrobat 的参数兼容。

因此,如果您的用户不使用 Adob​​e 阅读器扩展,大多数用户使用默认浏览器配置,则此参数可能不起作用。作为开发人员,我们无法控制用户在浏览器上配置了哪些插件/扩展来显示 PDF 文件。

另一种方法是使用 Mozilla 的 pdf.js 库,它可以在画布内呈现 pdf 文件。在此链接中,您将找到一些实时示例:https ://mozilla.github.io/pdf.js/examples/

这是一个常见问题,您可以在 Stack Overflow 和 mozilla 社区上找到一些关于它的问题:

如何在网页中嵌入 PDF 而不显示 Firefox PDF 查看器工具栏?

隐藏嵌入式pdf周围的工具栏?

在浏览器中显示 PDF 时可以隐藏 Adob​​e 浮动工具栏吗?

隐藏使用 firefox 在 iframe 中打开的 pdf 文件的工具栏(这个也有很好的解释)

隐藏嵌入式pdf周围的工具栏?

https://support.mozilla.org/nl/questions/1262019

https://support.mozilla.org/en-US/questions/1119523


推荐阅读