【问题标题】:Printing SSRS Report from Webforms app C#从 Webforms 应用程序 C# 打印 SSRS 报告
【发布时间】:2016-01-04 05:19:01
【问题描述】:

我正在尝试从用 C# 编写的网络表单应用程序打印 SSRS 报告。报告已加载到报告查看器中,到目前为止,这是我的代码:

    protected void printAll(object sender, EventArgs e)
    {
        //loads report into reportviewer
        showReport("/SHOW_ALL");

        string mimeType;
        string encoding;
        string extension;
        string[] streams;
        Warning[] warnings;
        byte[] pdfBytes = ReportViewer.ServerReport.Render("IMAGE", string.Empty, out mimeType,
            out encoding, out extension, out streams, out warnings);

        string outputPath = "C://Temp/";
        string outputFile = Path.GetFileName(ReportViewer.ServerReport.ReportPath) + "_" + client.FullName + ".tiff";
        string fullOutput = outputPath + outputFile;

        if (File.Exists(fullOutput))
        {
            File.Delete(fullOutput);
        }
        using (FileStream fs = new FileStream(fullOutput, FileMode.Create))
        { 
            fs.Write(pdfBytes, 0, pdfBytes.Length);
            fs.Close();
        }


    }

我只是想将图像写入 iFrame 并打印出来。我尝试过作为 PDF 格式,但 IE 不呈现任何内容(没有内置的 pdf 查看器),如果我使用 .tiff 选项,则除了第一页之外无法打印任何内容。我浏览了许多与 winforms 或各种其他技术相关的文章,但到目前为止没有任何帮助。跨浏览器的东西会很好,但目前我只是在寻找更适合 IE 的东西。

【问题讨论】:

    标签: c# asp.net reporting-services webforms


    【解决方案1】:

    这是我在之前的项目中尝试过的解决方案。希望对您有所帮助。

    private void Export(ServerReport report)
        {
            Microsoft.Reporting.WebForms.Warning[] webWarning = null;
    
            m_streams = new List<Stream>();
    
            NameValueCollection nvc = new NameValueCollection();
    
            string extension = null;
            string encoding = null;
            string mimeType = null;
            string type = "HTML4.0";
    
            Stream stream = report.Render(type, null, nvc, out mimeType, out extension);
            StreamReader f = new StreamReader(stream);
            string strHtml = f.ReadToEnd();
    
            int startStyle = strHtml.IndexOf("<style", StringComparison.OrdinalIgnoreCase);
            int closeStyle = strHtml.IndexOf("</style>", StringComparison.OrdinalIgnoreCase);
            string style = strHtml.Substring(startStyle, closeStyle - startStyle) + "</style>";
    
            string body = strHtml.Substring(strHtml.IndexOf("<body", StringComparison.OrdinalIgnoreCase));
            body = body.Replace("</html>", "");
            body = body.Replace("<body", "<div");
            body = body.Replace("</body>", "</div>");
    
            string script = @"
            <script type='text/javascript'>
                function print_me(idx) {
                    var browser = navigator.userAgent;
                    if (browser.indexOf('MSIE') >= 0) {
                        document.execCommand('print', false, null);
                    }
                    else {
                        window.print();
                    }
    
                }
    
                $(function () {
                    print_me();
                });
            </script>";
    
            expandPrintHtml.InnerHtml = style + body + script;           
    
        }
    

    【讨论】:

    • 感谢您的回答。在我的场景中,expandPrintHtml 是一个 iFrame,运行时,此代码似乎挂起并且根本不更新 innerHtml。你用的是什么元素?
    • 你可以使用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-02
    • 1970-01-01
    相关资源
    最近更新 更多