- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 html 模板,自去年 11 月以来我一直将其与 Flying Saucer PDF 一起使用。我最近重建了该项目,突然相同的 HTML 和相同的代码抛出了 NPE。我将范围缩小到页面计数器。当我删除它们时,它就起作用了。这是我的 html 示例,演示了该问题。
<?xml version="1.0" encoding="UTF-8" ?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<style type="text/css">
@page {
@top-right {
content: element(header);
}
}
#pagenumber:before {
content: counter(page);
}
#pagecount:before {
content: counter(pages);
}
</style>
</head>
<body>
<header id="header" class="clearfix">
<div class="page-header">
<span class="label">Order Status</span><br/>
Page <div id="pagenumber"></div> of <div id="pagecount"></div>
</div>
</header>
<div>Hello World</div>
</body>
</html>
我将其作为有效负载发送到一个小型网络服务,该服务使用 Flying Saucer 来渲染它并将其发回。这是我在服务中的代码:
@RequestMapping(value="/render", method= RequestMethod.POST)
public void renderPdf(@RequestBody String xhtmlContent, HttpServletResponse response) {
ITextRenderer renderer = new ITextRenderer();
renderer.setDocumentFromString(xhtmlContent);
renderer.layout(); //ERROR HAPPENS HERE
try {
response.addHeader("Content-disposition", "attachment;filename=invoice.pdf");
response.setContentType("application/x-octet-stream");
renderer.createPDF(response.getOutputStream());
} catch (Exception e) {
logger.error("Error creating pdf: ", e);
}
}
我得到以下堆栈跟踪:
java.lang.NullPointerException: null
at org.xhtmlrenderer.layout.breaker.Breaker.getLanguage(Breaker.java:136) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.breaker.Breaker.getBreakPointsProvider(Breaker.java:124) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.breaker.Breaker.doBreakText(Breaker.java:147) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.breaker.Breaker.breakText(Breaker.java:112) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.InlineBoxing.layoutText(InlineBoxing.java:848) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.InlineBoxing.layoutContent(InlineBoxing.java:201) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layoutInlineChildren(BlockBox.java:983) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layoutChildren(BlockBox.java:964) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:847) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:776) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:321) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:299) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.BlockBoxing.layoutContent(BlockBoxing.java:90) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layoutChildren(BlockBox.java:967) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:847) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:776) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:321) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:299) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.BlockBoxing.layoutContent(BlockBoxing.java:90) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layoutChildren(BlockBox.java:967) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:847) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:776) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:321) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:299) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.layout.BlockBoxing.layoutContent(BlockBoxing.java:90) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layoutChildren(BlockBox.java:967) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:847) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:776) ~[flying-saucer-core-9.1.4.jar:na]
at org.xhtmlrenderer.pdf.ITextRenderer.layout(ITextRenderer.java:229) ~[flying-saucer-pdf-9.1.4.jar:na]
at com.byrne.pdfprinter.pdf.PdfController.renderPdf(PdfController.java:26) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_112]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_112]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_112]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_112]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.5.4.jar:8.5.4]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:522) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1110) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425) [tomcat-embed-core-8.5.4.jar:8.5.4]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.4.jar:8.5.4]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_112]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_112]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.4.jar:8.5.4]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_112]
再次,让我重申一下,在我尝试重建它之前,这段代码是有效的。我没有更改我的 Flying Saucer 版本,但我在 Maven 中使用 RELEASE 作为我的版本。因此,为了确保没有问题,我指定了具体的版本号,可以追溯到它工作时的日期以及之前的一段时间,但它仍然会发生。
当我发布这篇文章时,我正在追踪源头,但还没有找到任何东西。
最佳答案
Flying Saucer 项目9.1.5版本修复了该问题。9.1.4 是罪魁祸首。
关于java - 为什么我在 Flying Saucer 中的柜台上突然出现 NPE?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43072996/
我正在做一个汉诺塔程序 - 有 3 个钉子,第 1 个钉子上有一堆磁盘,按从大到小的顺序排列(最大的在底部,最小的在顶部)。您现在要做的就是将所有磁盘从 peg 1 移动到 peg 3,您可以使用 p
我有一个这样的计数器: counter = Counter(['a','a','b','b','b','c']) 给出这个对象: Counter({'b': 3, 'a': 2, 'c': 1}) 然
我正在尝试使用bloc模式构建购物车,这是我第一个 flutter 的应用程序,也是使用bloc。我的问题是,每次用户将产品添加到购物车时,我都试图获取int流。但似乎我在使用接收器和流错误,但我不知
我正在编写一个Java应用程序,它有时会生成整数值。 java应用程序在Windows机器上运行。我不知道这是否可行,但我想知道是否可以为这些值创建一个 Windows 计数器“MyCounter”,
我有一个矩阵形状 (600, 900 亿) 保存为 *.txt 文件。矩阵的每一行由不同的样本名称 sample_name1、sample_name2 等命名。但是,有些样本名称未标准化,例如s###
更新:: 好的,所以我在头文件中添加了这些新行: static void gcdStatsCounter();//increments counter static void display(); /
我是一名优秀的程序员,十分优秀!