Obl*_*obl 3 c# asp.net-mvc fastreport
如何导出pdf使用FastReport.net和asp.net?我想在控制器中导出文件.我试过这种方式在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");
}
Run Code Online (Sandbox Code Playgroud)
但那时的大小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;
}
}
Run Code Online (Sandbox Code Playgroud)
遗憾的是,这些代码模板在开发人员的官方网站上是错误的.
| 归档时间: |
|
| 查看次数: |
9558 次 |
| 最近记录: |