Crystal 报告直接下载成 pdf C#

Crystal Reports directly download into pdf C#

我想直接下载 crystal 报告到 pdf 一起在 CommonReportViewer.aspx 页面查看,我 运行 我在本地服务器上的项目源 MYPROJECT 和 (.rpt) 报告D:\MYPROJECT\Reporting\Deposit\Reports。我在 Whosebug 上尝试了不同的解决方案,即 ExportToDisk、ExportOptions 等,但无法获得解决方案。在我查看银行报告的情况下,我通过表单提供了报告参数,最后到达报告参数并显示报告。我的问题是我如何才能直接以 pdf 格式下载该报告,因为我需要打印多页报告。

CommonReportViewer.aspx.cs:

  public partial class CommonReportViewer : System.Web.UI.Page
    {
        ReportDocument mainDoc = new ReportDocument();
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {

                CrystalReport report = new CrystalReport();
                report = (CrystalReport)Session["NLK_REPORT"];
                DateTime t1 = DateTime.Now;
                mainDoc.Load(report.ReportFilePath, OpenReportMethod.OpenReportByDefault);
                mainDoc.RecordSelectionFormula = report.SelectionCriteria;

                mainDoc.Refresh();
                string server = "NLKNEWDB";
                string userID = report.UserID;
                string password = report.Password;

                this.ApplyLogonInfo(mainDoc, server, userID, password);


                foreach (ReportParameter param in report.ParamList)
                {
                    mainDoc.SetParameterValue(param.ParamName, param.ParamValue);
                }

                foreach (SubReport sr in report.SubReportList)
                {
                    this.ApplyLogonInfo(mainDoc, server, userID, password);
                    foreach (ReportParameter param in sr.ParamList)
                    {

                        mainDoc.SetParameterValue(param.ParamName, param.ParamValue, sr.SubReportName);
                    }
                }

                mainDoc.SetDatabaseLogon(userID, password, server, "");

                this.crptViewer.ReportSource = mainDoc;

                mainDoc.DataSourceConnections.Clear();


            }
            finally
            {

            }
        }

        void ApplyLogonInfo(ReportDocument report, string server, string userID, string password)
        {
            TableLogOnInfo info = new TableLogOnInfo();
            ConnectionInfo cinfo = new ConnectionInfo();

            cinfo.ServerName = server;
            cinfo.UserID = userID;
            cinfo.Password = password;
            info.ConnectionInfo = cinfo;

            foreach (CrystalDecisions.CrystalReports.Engine.Table tbl in report.Database.Tables)
            {
                tbl.ApplyLogOnInfo(info);
            }
        }

        private void Page_Unload(object sender, System.EventArgs e)
        {
            if (mainDoc != null)
            {
                mainDoc.Close();
                mainDoc.Dispose();
            }

        }
    }

应进行一些更改以将其导出为 PDF 格式。当页面加载时,Page_Load 方法中的更改为。

 protected void Page_Load(object sender, EventArgs e)
        {
            try
            {

                CrystalReport report = new CrystalReport();
                report = (CrystalReport)Session["NLK_REPORT"];
                DateTime t1 = DateTime.Now;
                mainDoc.Load(report.ReportFilePath, OpenReportMethod.OpenReportByDefault);
                mainDoc.RecordSelectionFormula = report.SelectionCriteria;
                mainDoc.Refresh();

                string server = "NLKNEWDB";
                string userID = report.UserID;
                string password = report.Password;
                string empId = null;

                this.ApplyLogonInfo(mainDoc, server, userID, password);

                foreach (ReportParameter param in report.ParamList)
                {
                    mainDoc.SetParameterValue(param.ParamName, param.ParamValue);
                    if (param.ParamName == "P_EMPLOYER_ID")
                    {
                        empId = param.ParamValue.ToString();
                    }
                }

                foreach (SubReport sr in report.SubReportList)
                {
                    this.ApplyLogonInfo(mainDoc, server, userID, password);
                    foreach (ReportParameter param in sr.ParamList)
                    {

                        mainDoc.SetParameterValue(param.ParamName, param.ParamValue, sr.SubReportName);
                    }
                }

                mainDoc.SetDatabaseLogon(userID, password, server, "");
                mainDoc.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, true, empId);
                this.crptViewer.ReportSource = mainDoc;

                mainDoc.DataSourceConnections.Clear();




            }
            finally
            {

            }
        }