生成 PDF 文档时出现 GemBox 错误
GemBox error when generating PDF document
我在使用 GemBox.Document 在我的应用程序中生成 PDF 版本的搜索结果时遇到一个异常问题。当我返回大量记录时(尽管数量仍然很小),它似乎会发生。奇怪的是,如果我为所有记录的子集 A 和所有记录的子集 B 生成报告,但 not A 和 B 一起生成报告,则代码有效。在这三种情况下,DocumentModel 似乎都能正确生成;保存时出现错误。
相关方法如下:
public MemoryStream GetPdfReport(SearchRequestData searchRequestData, HttpRequest httpRequest)
{
_stream = new MemoryStream();
_httpRequest = httpRequest;
DocumentModel dm = CreateDocxOrPdfReport(searchRequestData);
dm.Save(_stream, GemBox.Document.SaveOptions.PdfDefault);
//CreateDocxOrPdfReport(searchRequestData).Save(_stream, GemBox.Document.SaveOptions.PdfDefault);
return _stream;
}
private DocumentModel CreateDocxOrPdfReport(SearchRequestData searchRequestData)
{
SetFieldsToDisplay(searchRequestData);
searchRequestData.PageIndex = 0;
var reportData = TrackService.GetTrackReportData(searchRequestData);
var doc = new DocumentModel();
var section = new Section(doc);
doc.Sections.Add(section);
AddDocxOrPdfHeaderAndFooter(doc, "Search Report");
AddDocxOrPdfFirstPageSummary(doc, "Search Report", reportData.Count, searchRequestData, ReportType.Track);
AddDocxOrPdfReportData(doc, doc.Sections[0], reportData);
return doc;
}
这里是错误:
System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=GemBox.Document
StackTrace:
at eh.k()
at eh.a(f6 A_0, ko A_1)
at b9.a(f6& A_0, Int32 A_1, gl A_2, v3 A_3, Int32& A_4, Boolean& A_5, ArrayList& A_6)
at b9.a(gl A_0, f6& A_1, Int32& A_2)
at b9.a(l4 A_0, gl A_1)
at ug.a(tz A_0, e6 A_1, gl A_2)
at pc.a(er A_0, er A_1, Double A_2, t1 A_3, Boolean A_4, ug A_5)
at pc.a(t1 A_0, t1 A_1, t1 A_2, Boolean A_3, ug A_4, d2 A_5, d2 A_6)
at pc.a(ir A_0, Double A_1, Boolean A_2, ug A_3)
at pc.a(x9 A_0, f6 A_1, ir A_2, ug A_3)
at pc.a(f6 A_0, ko A_1)
at b9.a(f6& A_0, Int32 A_1, gl A_2, v3 A_3, Int32& A_4, Boolean& A_5, ArrayList& A_6)
at b9.a(gl A_0, f6& A_1, Int32& A_2)
at b9.a(l4 A_0, gl A_1)
at b9.a(l4 A_0)
at qh.a(l4 A_0)
at a3.e()
at ai.a(Boolean A_0)
at ai.g()
at ai.c()
at vt.a()
at ow.a(Stream A_0, String A_1, String A_2, db A_3)
at vt.a(vw A_0, Stream A_1, String A_2, String A_3, db A_4)
at GemBox.Document.PdfSaveOptions.Save(DocumentModel document, Stream stream, String path)
at GemBox.Document.DocumentModel.Save(Stream stream, SaveOptions options)
at StateScape.API.Services.LocalTrackExportService.GetPdfReport(SearchRequestData searchRequestData, HttpRequest httpRequest) in c:\Users\Andrew\Documents\Projects\StateScape\git\statescapeweb\StateScape.API\Services\LocalTrackExportService.cs:line 27
at StateScape.API.Controllers.ExportReportController.GetLocalTrackPdf() in c:\Users\Andrew\Documents\Projects\StateScape\git\statescapeweb\StateScape.API\Controllers\ExportReportController.cs:line 244
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41()
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()
InnerException:
你好,你用 latest bug-fix version 重现了这个问题吗?
如果您愿意,是否可以向我们发送一个重现该问题的小型 VS 测试项目(连同输入文件),以便我们进行调查?
也可以随时 submit a support ticket 解决此问题(如果可能,请提供更多详细信息)。
原来解决方案是使用正则表达式检查不可打印的字符。我仍然不确定为什么这些字符只在组合结果集时出现,但这对我有用。
我在使用 GemBox.Document 在我的应用程序中生成 PDF 版本的搜索结果时遇到一个异常问题。当我返回大量记录时(尽管数量仍然很小),它似乎会发生。奇怪的是,如果我为所有记录的子集 A 和所有记录的子集 B 生成报告,但 not A 和 B 一起生成报告,则代码有效。在这三种情况下,DocumentModel 似乎都能正确生成;保存时出现错误。
相关方法如下:
public MemoryStream GetPdfReport(SearchRequestData searchRequestData, HttpRequest httpRequest)
{
_stream = new MemoryStream();
_httpRequest = httpRequest;
DocumentModel dm = CreateDocxOrPdfReport(searchRequestData);
dm.Save(_stream, GemBox.Document.SaveOptions.PdfDefault);
//CreateDocxOrPdfReport(searchRequestData).Save(_stream, GemBox.Document.SaveOptions.PdfDefault);
return _stream;
}
private DocumentModel CreateDocxOrPdfReport(SearchRequestData searchRequestData)
{
SetFieldsToDisplay(searchRequestData);
searchRequestData.PageIndex = 0;
var reportData = TrackService.GetTrackReportData(searchRequestData);
var doc = new DocumentModel();
var section = new Section(doc);
doc.Sections.Add(section);
AddDocxOrPdfHeaderAndFooter(doc, "Search Report");
AddDocxOrPdfFirstPageSummary(doc, "Search Report", reportData.Count, searchRequestData, ReportType.Track);
AddDocxOrPdfReportData(doc, doc.Sections[0], reportData);
return doc;
}
这里是错误:
System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=GemBox.Document
StackTrace:
at eh.k()
at eh.a(f6 A_0, ko A_1)
at b9.a(f6& A_0, Int32 A_1, gl A_2, v3 A_3, Int32& A_4, Boolean& A_5, ArrayList& A_6)
at b9.a(gl A_0, f6& A_1, Int32& A_2)
at b9.a(l4 A_0, gl A_1)
at ug.a(tz A_0, e6 A_1, gl A_2)
at pc.a(er A_0, er A_1, Double A_2, t1 A_3, Boolean A_4, ug A_5)
at pc.a(t1 A_0, t1 A_1, t1 A_2, Boolean A_3, ug A_4, d2 A_5, d2 A_6)
at pc.a(ir A_0, Double A_1, Boolean A_2, ug A_3)
at pc.a(x9 A_0, f6 A_1, ir A_2, ug A_3)
at pc.a(f6 A_0, ko A_1)
at b9.a(f6& A_0, Int32 A_1, gl A_2, v3 A_3, Int32& A_4, Boolean& A_5, ArrayList& A_6)
at b9.a(gl A_0, f6& A_1, Int32& A_2)
at b9.a(l4 A_0, gl A_1)
at b9.a(l4 A_0)
at qh.a(l4 A_0)
at a3.e()
at ai.a(Boolean A_0)
at ai.g()
at ai.c()
at vt.a()
at ow.a(Stream A_0, String A_1, String A_2, db A_3)
at vt.a(vw A_0, Stream A_1, String A_2, String A_3, db A_4)
at GemBox.Document.PdfSaveOptions.Save(DocumentModel document, Stream stream, String path)
at GemBox.Document.DocumentModel.Save(Stream stream, SaveOptions options)
at StateScape.API.Services.LocalTrackExportService.GetPdfReport(SearchRequestData searchRequestData, HttpRequest httpRequest) in c:\Users\Andrew\Documents\Projects\StateScape\git\statescapeweb\StateScape.API\Services\LocalTrackExportService.cs:line 27
at StateScape.API.Controllers.ExportReportController.GetLocalTrackPdf() in c:\Users\Andrew\Documents\Projects\StateScape\git\statescapeweb\StateScape.API\Controllers\ExportReportController.cs:line 244
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41()
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()
InnerException:
你好,你用 latest bug-fix version 重现了这个问题吗? 如果您愿意,是否可以向我们发送一个重现该问题的小型 VS 测试项目(连同输入文件),以便我们进行调查? 也可以随时 submit a support ticket 解决此问题(如果可能,请提供更多详细信息)。
原来解决方案是使用正则表达式检查不可打印的字符。我仍然不确定为什么这些字符只在组合结果集时出现,但这对我有用。