我正在使用 C# (.NET 4) 从属于我的应用程序的 Crystal RPT 文件生成并返回 PDF。它间歇性地工作,但生成 PDF 的速度非常慢(有时根本无法完成)。关于下面代码的任何建议可能会为我指明正确的方向?
// POST: /API/GetReport
[HttpPost]
public ActionResult GetReport()
{
BoolResponse response = new BoolResponse { };
string evalID = Request["evalID"] ?? "";
if (evalID != "" && UserCanViewEval(evalID)) {
ReportClass rptH = new ReportClass();
try
{
ParameterField paramField = new ParameterField();
ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
ParameterValues paramValues = new ParameterValues();
rptH.FileName = Server.MapPath("~/Content/Reports/Eval.rpt");
rptH.Load();
rptH.SetParameterValue("EvalID", evalID);
Stream stream = rptH.ExportToStream(ExportFormatType.PortableDocFormat);
stream.Seek(0, System.IO.SeekOrigin.Begin);
return new FileStreamResult(stream, "application/pdf");
}
catch (Exception e)
{
response.errors = e.Message;
return Json(response, JsonRequestBehavior.AllowGet);
}
finally {
rptH.Close();
rptH.Dispose();
}
}
else {
return View();
}
}