c# – 使用FastReport.net和asp.net导出pdf
发布时间:2020-12-16 01:56:35 所属栏目:百科 来源:网络整理
导读:如何使用FastReport.net和asp.net导出pdf? 我想在控制器中导出文件.我试过这种方式在FastReport网站上支持: public FileResult GetFile() { WebReport webReport = new WebReport(); // bind data System.Data.DataSet dataSet = new System.Data.DataSet(
如何使用FastReport.net和asp.net导出pdf?
我想在控制器中导出文件.我试过这种方式在FastReport网站上支持: public FileResult GetFile() { WebReport webReport = new WebReport(); // bind data System.Data.DataSet dataSet = new System.Data.DataSet(); dataSet.ReadXml(report_path + "nwind.xml"); webReport.Report.RegisterData(dataSet,"NorthWind"); // load report webReport.ReportFile = this.Server.MapPath("~/App_Data/report.frx"); // prepare report webReport.Report.Prepare(); // save file in stream Stream stream = new MemoryStream(); webReport.Report.Export(new PDFExport(),stream); stream.Position = 0; // return stream in browser return File(stream,"application/zip","report.pdf"); } 但是pdf的大小总是0字节. 有人知道我的问题的解决方案吗? 解决方法
好的,现在我找到了解决方案.只需使用正常的Report(而不是WebReport)并将WebMode设置为true. pdf-Export上的其他设置只是为了好玩.
所以,这将成功: public FileResult GetFile(Dataset dataset1) { FastReport.Utils.Config.WebMode = true; Report rep = new Report(); rep.Load(Request.PhysicalApplicationPath + "App_Data/report.frx"); rep.RegisterData(dataset1); if (rep.Report.Prepare()) { // Set PDF export props FastReport.Export.Pdf.PDFExport pdfExport = new FastReport.Export.Pdf.PDFExport(); pdfExport.ShowProgress = false; pdfExport.Subject = "Subject"; pdfExport.Title = "xxxxxxx"; pdfExport.Compressed = true; pdfExport.AllowPrint = true; pdfExport.EmbeddingFonts = true; MemoryStream strm = new MemoryStream(); rep.Report.Export(pdfExport,strm); rep.Dispose(); pdfExport.Dispose(); strm.Position = 0; // return stream in browser return File(strm,"application/pdf","report.pdf"); } else { return null; } } 遗憾的是,这些代码模板在开发人员的官方网站上是错误的. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |