当我使用
时'page-break-always: always'
表中的样式。解析器抛出以下异常:
"Message": "An error has occurred.",
"ExceptionMessage": "",
"ExceptionType": "iTextSharp.tool.xml.exceptions.RuntimeWorkerException",
"StackTrace": " at iTextSharp.tool.xml.XMLWorker.StartElement(String tag, IDictionary`2 attr, String ns)\r\n at iTextSharp.tool.xml.parser.XMLParser.StartElement()\r\n at iTextSharp.tool.xml.parser.state.TagEncounteredState.Process(Char character)\r\n at iTextSharp.tool.xml.parser.XMLParser.ParseWithReader(TextReader reader)\r\n at HtmlToPDFAPi_ITextSharp.Controllers.PdfController.SavePDFFromHTML() in C:\\Users\\pshankhareman.DOMAIN\\documents\\visual studio 2015\\Projects\\HtmlToPDF\\HtmlToPDFAPi_ITextSharp\\Controllers\\PdfController.cs:line 84\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()",
"InnerException": {
"Message": "An error has occurred.",
"ExceptionMessage": "iTextSharp.tool.xml.pipeline.css.CssResolverPipeline cries, it cannot find it's own context.",
"ExceptionType": "iTextSharp.tool.xml.PipelineException",
"StackTrace": " at iTextSharp.tool.xml.pipeline.AbstractPipeline.GetLocalContext(IWorkerContext context)\r\n at iTextSharp.tool.xml.pipeline.css.CssResolverPipeline.Open(IWorkerContext context, Tag t, ProcessObject po)\r\n at iTextSharp.tool.xml.XMLWorker.StartElement(String tag, IDictionary`2 attr, String ns)",
"InnerException": {
"Message": "An error has occurred.",
"ExceptionMessage": "Exception of type 'iTextSharp.tool.xml.NoCustomContextException' was thrown.",
"ExceptionType": "iTextSharp.tool.xml.NoCustomContextException",
"StackTrace": " at iTextSharp.tool.xml.pipeline.ctx.WorkerContextImpl.Get(String klass)\r\n at iTextSharp.tool.xml.pipeline.AbstractPipeline.GetLocalContext(IWorkerContext context)"
}
}
我也试过将样式添加到div元素中。它似乎不起作用。它会抛出相同的错误。
只有当作者有“OnEndPage”时才会抛出异常。与之相关的事件。如果删除事件,它可以正常工作,但需要在页面中添加页脚。
我做错了什么吗?有没有更好的方法可以强制div进入新页面?
更新
我已经意识到只有当我尝试在事件监听器中解析html页脚时才会发生这种情况。
我这样做:
footer=XMLWorkerHelper.ParseToElementList(footerHTML.Replace("pageNum", document.PageNumber.ToString()).Replace("updateDate", date), footerCss);
一旦它回到解析方法,它就会失败抛出上述错误。