Chrome和Firefox中的SSRS打印按钮
我在SSRS 2005中有报告。我正在使用远程报告。 在IE中,打印按钮显示,但在Firefox和Chrome中,打印按钮不显示。
我的报告显示在jquery UI对话框中,所以我不能只做一个window.print。 我的报告在模态中呈现得很好。
我需要能够以与在控件中完成相同的方式向reportviewer发出打印命令,但仅限于firefox和chrome。
我挖了报告查看器的标记,找到了这段代码。 我试图手动将其注入reportviewer但没有成功。
document.getElementById('reportViewer_ctl01_ctl07_ctl00_ctl00').Controller = new ReportViewerHoverButton("reportViewer_ctl01_ctl07_ctl00_ctl00", false, "", "", "", "#ECE9D8", "#DDEEF7", "#99BBE2", "1px #ECE9D8 Solid", "1px #336699 Solid", "1px #336699 Solid");
有任何想法吗?
不幸的是,IE以外的浏览器不支持打印按钮。
我认为你意识到这一点并做了一个解决方法,我们还没有提出一个像样的解决方案。 虽然我们的大多数用户更喜欢直接从Excel打印,但我们允许他们导出文件然后进行打印。
这个SO问题将是一个很好的链接:
SQL Reporting Services – 打印按钮未在Mozilla中显示
这是我创建一个伪打印按钮,它将Internet Explorer中的报表查看器的打印function模拟到其他浏览器。
请注意,下面的解决方案需要JQuery。 无需安装ActiveX。
这是步骤。
步骤1.在页面中添加报表查看器所在的打印按钮。
请务必将版本号更改为RS版本。 如果您在使用html代码时遇到问题,可以使用Internet Explorer打开该页面并检查print元素并进行复制。
步骤2.添加将在其中呈现PDF的div。
第3步。添加脚本。
$(document).ready(function () { // Check if the current browser is IE (MSIE is not used since IE 11) var isIE = /MSIE/i.test(navigator.userAgent) || /rv:11.0/i.test(navigator.userAgent); function printReport() { var reportViewerName = 'ReportViewer'; //Name attribute of report viewer control. var src_url = $find(reportViewerName)._getInternalViewer().ExportUrlBase + 'PDF'; var contentDisposition = 'AlwaysInline'; //Content Disposition instructs the server to either return the PDF being requested as an attachment or a viewable report. var src_new = src_url.replace(/(ContentDisposition=).*?(&)/, '$1' + contentDisposition + '$2'); var iframe = $('
代码说明:
首先,我们创建了一个变量,用于检测浏览器是否为IE。
通过使用Reserved.ReportViewerWebControl.axd中的_getInternalViewer()方法,我们可以请求报告的PDF版本作为最初在单击导出按钮时检索的请求。
然后,我们将contentDisposition变量指定为“AlwaysInline”,因为我们要将报告请求为PDF,而不是作为附件,而是作为PDF,我们可以在html元素中呈现。 https://msdn.microsoft.com/en-us/library/microsoft.reporting.webforms.reportviewer.exportcontentdisposition.aspx
src_new变量使用我们的新请求’AlwaysInline’替换默认的EXPORT按钮内容处理请求(默认情况下设置为AlwaysAttachment)。
接下来,我们将iframe的src设置为我们的新url,加载后,将从reportviewer中将我们的报告显示为PDF。
iframe中的链式命令包括隐藏pdf元素,渲染它并在完成加载pdf后立即打印它。
结束语
我希望有人会发现这个代码很有用,因为我很难在网上找到一个像样的解决方案,而这正是我在做了一些研究之后想出来的。
请找到具有适用于Firefox和Chrome的打印function的打印图标的SSRS报告代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Report.aspx.cs" Inherits="DemoMVC.Report.Report" %> <%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
我对上述内容进行了一些更改,在Chrome和Firefox中都适用于我。
function PrintReport() { var reportViewerName = 'ReportViewer1'; var src_url = $find(reportViewerName)._getInternalViewer().ExportUrlBase + 'PDF'; var contentDisposition = 'AlwaysInline'; var src_new = src_url.replace(/(ContentDisposition=).*?(&)/, '$1' + contentDisposition + '$2'); var iframe = $('