在VS2008中,利用VS2008自带的CrystalReport做报表开发。前台页面点击一个button,页面会在CrystalReportViewer控件显示报表内容。打印直接点击CrystalReportViewer控件的打印button。此时CrystalReportViewer控件会将报表默认导出到pdf中。现在我想在页面不用CrystalReportViewer控件显示,而是直接点击一个button,直接将报表内容显示在pdf中,请问大家如何实现该功能?

解决方案 »

  1.   

    是否可以理解成不显示报表,可是可以看见打印的效果导入到pdf文件中,呵呵,如果微软开放了接口哪有可能实现,不然基本无解
      

  2.   

    to:楼上
    嗯,就那么理解。就是打击button后直接将报表内容显示在pdf文件中~~
      

  3.   

    CrystalReport可以直接导出为PDF,调用那个方法就可以了吧,几年前做过,但很久没再用了,具体的代码忘了,可以看看这个:http://www.cnblogs.com/yqy542006/archive/2007/05/14/745564.html
      

  4.   

    而是直接点击一个button,直接将报表内容显示在pdf中
    ----
    y要么显示在VIEW中,要么直接就打印了,用PRINTTOPRINT方法
      

  5.   

    直接导出PDF我写过个代码,给你看看using CrystalDecisions.CrystalReports.Engine;CrystalDecisions.Shared.DiskFileDestinationOptions opts = new CrystalDecisions.Shared.DiskFileDestinationOptions();
    //导出为磁盘文件
    CrystalDecisions.Shared.ExportOptions myExportOptions =reportDoc.ExportOptions;
    myExportOptions.DestinationOptions = opts;
    myExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
    //导出为pdf格式
    reportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
    //目的路径

    opts.DiskFileName =this.saveFileDialog1.FileName;
    //导出操作
    reportDoc.Export();
      

  6.   

    http://www.cnblogs.com/downmoon/archive/2008/12/08/1350008.html
      

  7.   

    跟踪水晶报表的后台js,自己在页面上写同样的js来实现;
      

  8.   

    先生成 string fileName = string.Empty;
                string fileFullName = string.Empty;
                try
                {
                    CrystalDecisions.Shared.DiskFileDestinationOptions crFileOptions = new CrystalDecisions.Shared.DiskFileDestinationOptions();
                    fileName = Guid.NewGuid().ToString().Substring(0, 8) + ".pdf";
                    fileFullName = HttpContext.Current.Server.MapPath("~/Report/") + fileName;
                    crFileOptions.DiskFileName = fileFullName;                RptDoc.ExportOptions.DestinationOptions = crFileOptions;
                    RptDoc.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                    RptDoc.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
                    RptDoc.Export();
                }
                catch(Exception exobj)
                {
                    fileFullName = string.Empty;
                    throw exobj;
                }
                finally
                {
                    RptDoc.Close();
                } public void ExportToExplorer(string contentType, string fileName, string fileFullName)
            {
                if (File.Exists(fileFullName))
                {                // Get length of file
                    long fileLength = new FileInfo(fileFullName).Length;                // Clear response information
                    HttpContext.Current.Response.Clear();
                    HttpContext.Current.Response.ClearContent();
                    HttpContext.Current.Response.ClearHeaders();                // Set encoding format
                    HttpContext.Current.Response.Charset = "UTF-8";
                    HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;                // Add header information to response
                    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
                    HttpContext.Current.Response.AddHeader("Context-Length", fileLength.ToString());                // Set content type
                    HttpContext.Current.Response.ContentType = contentType;                // Export report to explorer
                    HttpContext.Current.Response.WriteFile(fileFullName);
                    HttpContext.Current.Response.Flush();
                }
            }