【问题标题】:Save SSRS Report as pdf using Reporting Services使用 Reporting Services 将 SSRS 报告另存为 pdf
【发布时间】:2014-01-04 21:56:08
【问题描述】:

我一直在尝试使用 Reporting Web Services 将 SSRS 报告转换为 PDF 并保存到我的本地驱动器。虽然我能够生成相应的 pdf 文件,但文件的内容丢失了。我检查了我要转换的报告不是空的。生成的 pdf 文件中仅存在标题部分。以下是我正在使用的代码:

protected void GeneratePDFFromReport(object sender, EventArgs e)
    {
        RS2005.ReportingService2005 rs;
        RE2005.ReportExecutionService rsExec;

        // Create a new proxy to the web service
        rs = new RS2005.ReportingService2005();
        rsExec = new RE2005.ReportExecutionService();

        // Authenticate to the Web service using Windows credentials
        rs.Credentials = new System.Net.NetworkCredential("username", "password", "domain");
        rsExec.Credentials = new System.Net.NetworkCredential("username", "password", "domain");
        //rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials;

        rs.Url = "http://servername/reportserver/reportservice2005.asmx";
        rsExec.Url = "http://servername/reportserver/reportexecution2005.asmx";

        string historyID = null;
        string deviceInfo = null;
        string format = "PDF";
        Byte[] results;
        string encoding = String.Empty;
        string mimeType = "application/pdf";
        string extension = String.Empty;
        RE2005.Warning[] warnings = null;
        string[] streamIDs = null;

        // Path of the Report - XLS, PDF etc.
        string fileName = @"C:\Report\MemberReport.pdf";
        // Name of the report - Please note this is not the RDL file.
        string _reportName = @"/ReportFolder/ReportName";
        string _historyID = null;
        bool _forRendering = false;
        RS2005.ParameterValue[] _values = null;
        RS2005.DataSourceCredentials[] _credentials = null;
        RS2005.ReportParameter[] _parameters = null;

        try
        {
            _parameters = rs.GetReportParameters(_reportName, _historyID, _forRendering, _values, _credentials);
            RE2005.ExecutionInfo ei = rsExec.LoadReport(_reportName, historyID);

            results = rsExec.Render(format, deviceInfo,
                      out extension, out encoding,
                      out mimeType, out warnings, out streamIDs);

            try
            {
                FileStream stream = File.Create(fileName, results.Length);
                stream.Write(results, 0, results.Length);
                stream.Close();
            }
            catch { }

            results = null;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

任何帮助将不胜感激。谢谢。

【问题讨论】:

    标签: pdf reporting-services ssrs-2008


    【解决方案1】:

    假设 SSRS 使用浏览器工作正常,请修改您发布的代码,如下所示:

    1) 设备信息字符串,请按如下方式设置:

    string deviceInfo =  @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"; //Initial value was null
    

    2) 使用Web调用LoadReport之前创建Header实例:

    ExecutionHeader execHeader = new ExecutionHeader();
    RE2005.ExecutionHeaderValue = execHeader;
    

    【讨论】:

      猜你喜欢
      • 2010-10-22
      • 1970-01-01
      • 1970-01-01
      • 2023-01-12
      • 1970-01-01
      • 1970-01-01
      • 2010-09-15
      • 2011-12-29
      • 2019-03-21
      相关资源
      最近更新 更多