在 asp.net c# 上将 fastreport 导出为 pdf 时出错
Error in exporting fastreport to pdf on asp.net c#
我想将由 FastReport
设计的 .frx
报告导出为 pdf 或 excel 文件到 c# web 表单应用程序,如下代码所示:
public static bool ShowReport(string ReportFileName, DataTable ReportData, string DBObjectName, string ExportType, out string Message, params string[] AdditionalParams)
{
FastReport.Utils.Config.WebMode = true;
string ReportFile = HttpContext.Current.Server.MapPath(WPResources.ReportsRoot) + string.Format("{0}_{1}.frx", ReportFileName, ExportType.ToUpper());
FastReport.Report objReport = new FastReport.Report();
objReport.Load(ReportFile);
objReport.Dictionary.Connections.Clear();
System.Data.DataTable resultTable = new DataTable();
objReport.RegisterData(ReportData, DBObjectName);
objReport.GetDataSource(DBObjectName).Enabled = true;
int ParamsCount = AdditionalParams.Length;
if ((ParamsCount % 2) != 0)
ParamsCount--;
for (int i = 0; i < ParamsCount; i += 2)
{
var DynamicControl = (objReport.FindObject(AdditionalParams[i]) as FastReport.TextObject);
if (DynamicControl != null)
{
DynamicControl.Text = AdditionalParams[i + 1];
DynamicControl.Visible = !string.IsNullOrEmpty(AdditionalParams[i + 1]);
}
}
(objReport.FindObject("rptData") as FastReport.DataBand).DataSource = objReport.GetDataSource(DBObjectName);
string fileName = Path.GetFileNameWithoutExtension(ReportFile);
fileName += "_" + WPFarsiDate.Today.ToString().Replace("/", ".") + "_" +
DateTime.Now.Hour.ToString() + "." +
DateTime.Now.Minute.ToString();
if (ExportType == "Excel")
{
using (MemoryStream objMemoryStream = new MemoryStream())
{
objReport.Prepare(false);
FastReport.Export.OoXML.Excel2007Export objExcel2007Export = new FastReport.Export.OoXML.Excel2007Export();
objExcel2007Export.OpenAfterExport = false;
objExcel2007Export.Export(objReport, objMemoryStream);
byte[] buffer = objMemoryStream.ToArray();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("inline;filename={0}.xlsx", fileName));
HttpContext.Current.Response.BinaryWrite(buffer);
HttpContext.Current.Response.End();
}
}
else if (ExportType == "Pdf")
{
using (MemoryStream objMemoryStream = new MemoryStream())
{
objReport.Prepare(false);
FastReport.Export.Pdf.PDFExport objPDFExport = new FastReport.Export.Pdf.PDFExport();
objPDFExport.EmbeddingFonts = true;
objPDFExport.OpenAfterExport = false;
objPDFExport.Export(objReport, objMemoryStream);
byte[] buffer = objMemoryStream.ToArray();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}.pdf", fileName));
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.BinaryWrite(buffer);
HttpContext.Current.Response.End();
}
}
Message = string.Empty;
return true;
}
当我把它导出到excel时,这没有任何关系,它会成功完成。但是当我将其导出为 pdf 时,出现此错误:
Showing a modal dialog box or form when the application is not running
in UserInteractive mode is not a valid operation. Specify the
ServiceNotification or DefaultDesktopOnly style to display a
notification from a service application.
需要注意的是,上述错误只是发生在主服务器上,在localhost上可以成功完成作业。
如果有人能解释这个问题的解决方案,那将非常有帮助。
你试过调试吗?哪一行抛出这个错误?
您在桌面版中看到任何对话框 windows 了吗?尽量避免。
经过一番努力,我找到了解决问题的方法。 .frx 文件中使用的字体不是 windows/fonts 文件夹。所以我在那里复制了提到的字体并且它工作正常。
我在我的一个 ASP.Net Web 表单项目中使用快速报告,当我尝试导出 PDF 时看到此异常。我在 .aspx 文件中有这个标签:
<fastreport:webreport id="remainedLeave" runat="server"
Width="100%" Height="100%"></fastreport:webreport>
将此 属性 添加到快速报告标签解决了我的问题:
PdfEmbeddingFonts="false"
我想将由 FastReport
设计的 .frx
报告导出为 pdf 或 excel 文件到 c# web 表单应用程序,如下代码所示:
public static bool ShowReport(string ReportFileName, DataTable ReportData, string DBObjectName, string ExportType, out string Message, params string[] AdditionalParams)
{
FastReport.Utils.Config.WebMode = true;
string ReportFile = HttpContext.Current.Server.MapPath(WPResources.ReportsRoot) + string.Format("{0}_{1}.frx", ReportFileName, ExportType.ToUpper());
FastReport.Report objReport = new FastReport.Report();
objReport.Load(ReportFile);
objReport.Dictionary.Connections.Clear();
System.Data.DataTable resultTable = new DataTable();
objReport.RegisterData(ReportData, DBObjectName);
objReport.GetDataSource(DBObjectName).Enabled = true;
int ParamsCount = AdditionalParams.Length;
if ((ParamsCount % 2) != 0)
ParamsCount--;
for (int i = 0; i < ParamsCount; i += 2)
{
var DynamicControl = (objReport.FindObject(AdditionalParams[i]) as FastReport.TextObject);
if (DynamicControl != null)
{
DynamicControl.Text = AdditionalParams[i + 1];
DynamicControl.Visible = !string.IsNullOrEmpty(AdditionalParams[i + 1]);
}
}
(objReport.FindObject("rptData") as FastReport.DataBand).DataSource = objReport.GetDataSource(DBObjectName);
string fileName = Path.GetFileNameWithoutExtension(ReportFile);
fileName += "_" + WPFarsiDate.Today.ToString().Replace("/", ".") + "_" +
DateTime.Now.Hour.ToString() + "." +
DateTime.Now.Minute.ToString();
if (ExportType == "Excel")
{
using (MemoryStream objMemoryStream = new MemoryStream())
{
objReport.Prepare(false);
FastReport.Export.OoXML.Excel2007Export objExcel2007Export = new FastReport.Export.OoXML.Excel2007Export();
objExcel2007Export.OpenAfterExport = false;
objExcel2007Export.Export(objReport, objMemoryStream);
byte[] buffer = objMemoryStream.ToArray();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("inline;filename={0}.xlsx", fileName));
HttpContext.Current.Response.BinaryWrite(buffer);
HttpContext.Current.Response.End();
}
}
else if (ExportType == "Pdf")
{
using (MemoryStream objMemoryStream = new MemoryStream())
{
objReport.Prepare(false);
FastReport.Export.Pdf.PDFExport objPDFExport = new FastReport.Export.Pdf.PDFExport();
objPDFExport.EmbeddingFonts = true;
objPDFExport.OpenAfterExport = false;
objPDFExport.Export(objReport, objMemoryStream);
byte[] buffer = objMemoryStream.ToArray();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}.pdf", fileName));
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.BinaryWrite(buffer);
HttpContext.Current.Response.End();
}
}
Message = string.Empty;
return true;
}
当我把它导出到excel时,这没有任何关系,它会成功完成。但是当我将其导出为 pdf 时,出现此错误:
Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
需要注意的是,上述错误只是发生在主服务器上,在localhost上可以成功完成作业。 如果有人能解释这个问题的解决方案,那将非常有帮助。
你试过调试吗?哪一行抛出这个错误? 您在桌面版中看到任何对话框 windows 了吗?尽量避免。
经过一番努力,我找到了解决问题的方法。 .frx 文件中使用的字体不是 windows/fonts 文件夹。所以我在那里复制了提到的字体并且它工作正常。
我在我的一个 ASP.Net Web 表单项目中使用快速报告,当我尝试导出 PDF 时看到此异常。我在 .aspx 文件中有这个标签:
<fastreport:webreport id="remainedLeave" runat="server"
Width="100%" Height="100%"></fastreport:webreport>
将此 属性 添加到快速报告标签解决了我的问题:
PdfEmbeddingFonts="false"