简体   繁体   English

Crystal Reports-在MVC中导出为pdf

[英]Crystal Reports - export to pdf in MVC

I have integrated the below code in my application to generate a 'pdf' file using crystal reports in MVC project. 我在我的应用程序中集成了以下代码,以使用MVC项目中的Crystal报表生成“ pdf”文件。 However, after the request is processed, i get to see only 2 pages in the pdf file while my 'data' returns more than 2 records. 但是,在处理了请求之后,我只能在pdf文件中看到2页,而我的“数据”返回的记录超过2条。 Also, the pdf isn't rendered as soon as the page is processed but instead i have to refresh atleast once, then the pdf is rendered on the browser. 另外,页面处理后不会立即呈现pdf,但是我必须至少刷新一次,然后才能在浏览器中呈现pdf。

using CrystalDecisions.CrystalReports.Engine;

public FileStreamResult Report()
{
    ReportClass rptH = new ReportClass();
    List<sampledataset> data = objdb.getdataset();
    rptH.FileName = Server.MapPath("[reportName].rpt");
    rptH.Load();
    rptH.SetDatabaseLogon("un", "pwd", "server", "db");
    rptH.SetDataSource(data);
    Stream stream = rptH.ExportToStream
       (CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
    stream.Seek(0, System.IO.SeekOrigin.Begin);
    return new FileStreamResult(stream, "application/pdf");   
}

I took the code from here in SO but modified it like above. 我把代码从这里的SO,但修改了它喜欢的上方。

TIA. TIA。

EDIT : This works on Firefox, not in IE7. 编辑 :这适用于Firefox,而不是IE7。

I finally found the solution here on SO. 我终于在这里找到了解决方案。 It had nothing to do with MVC but the way IE treats popup window. 它与MVC无关,而是IE处理弹出窗口的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM