主要代码
OutputStream os = new FileOutputStream(pdf);
ITextRenderer renderer = new ITextRenderer();
try {
renderer.setDocument(uri);
} catch (Exception e) {
os.flush();
os.close();
System.out.println("!!!!!!!!!!转换出错的链接: "+uri);
e.printStackTrace();
}
// 解决中文问题
ITextFontResolver fontResolver = renderer.getFontResolver();
String fonts=basePath+"/common/fonts/simsun.ttc";
fontResolver.addFont(fonts,BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
renderer.layout();
renderer.createPDF(os);
os.close();
return pdf;
报错信息:
[4/8/16 11:07:15:823 CST] 0000001b SystemErr R org.xhtmlrenderer.util.XRRuntimeException: Can't load the XML resource (using TRaX transformer). java.io.IOException: Stream closed
[4/8/16 11:07:15:824 CST] 0000001b SystemErr R at org.xhtmlrenderer.resource.XMLResource$XMLResourceBuilder.createXMLResource(XMLResource.java:191)
[4/8/16 11:07:15:824 CST] 0000001b SystemErr R at org.xhtmlrenderer.resource.XMLResource.load(XMLResource.java:71)
[4/8/16 11:07:15:824 CST] 0000001b SystemErr R at org.xhtmlrenderer.swing.NaiveUserAgent.getXMLResource(NaiveUserAgent.java:211)
[4/8/16 11:07:15:824 CST] 0000001b SystemErr R at org.xhtmlrenderer.pdf.ITextRenderer.loadDocument(ITextRenderer.java:134)
[4/8/16 11:07:15:824 CST] 0000001b SystemErr R at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:138)
[4/8/16 11:07:15:825 CST] 0000001b SystemErr R at com.topsoft.util.HtmlToPdfUtil.toPdf(HtmlToPdfUtil.java:49)
[4/8/16 11:07:15:825 CST] 0000001b SystemErr R at com.topsoft.action.register.EnterpriseRegisterAction.toPdf(EnterpriseRegisterAction.java:5725)
[4/8/16 11:07:15:825 CST] 0000001b SystemErr R at com.topsoft.action.register.EnterpriseRegisterAction.saveMail(EnterpriseRegisterAction.java:3599)
[4/8/16 11:07:15:825 CST] 0000001b SystemErr R at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[4/8/16 11:07:15:825 CST] 0000001b SystemErr R at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
[4/8/16 11:07:15:825 CST] 0000001b SystemErr R at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[4/8/16 11:07:15:825 CST] 0000001b SystemErr R at java.lang.reflect.Method.invoke(Method.java:600)
[4/8/16 11:07:15:825 CST] 0000001b SystemErr R at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
[4/8/16 11:07:15:825 CST] 0000001b SystemErr R at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
[4/8/16 11:07:15:825 CST] 0000001b SystemErr R at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
[4/8/16 11:07:15:825 CST] 0000001b SystemErr R at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
[4/8/16 11:07:15:825 CST] 0000001b SystemErr R at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
[4/8/16 11:07:15:825 CST] 0000001b SystemErr R at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
[4/8/16 11:07:15:825 CST] 0000001b SystemErr R at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
[4/8/16 11:07:15:825 CST] 0000001b SystemErr R at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
[4/8/16 11:07:15:825 CST] 0000001b SystemErr R at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
[4/8/16 11:07:15:825 CST] 0000001b SystemErr R at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
[4/8/16 11:07:15:825 CST] 0000001b SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
[4/8/16 11:07:15:826 CST] 0000001b SystemErr R at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
[4/8/16 11:07:15:826 CST] 0000001b SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
[4/8/16 11:07:15:826 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1661)
[4/8/16 11:07:15:826 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1602)
[4/8/16 11:07:15:826 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:149)
[4/8/16 11:07:15:826 CST] 0000001b SystemErr R at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:152)
[4/8/16 11:07:15:826 CST] 0000001b SystemErr R at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
[4/8/16 11:07:15:826 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
[4/8/16 11:07:15:826 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:125)
[4/8/16 11:07:15:826 CST] 0000001b SystemErr R at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
[4/8/16 11:07:15:826 CST] 0000001b SystemErr R at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
[4/8/16 11:07:15:826 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
[4/8/16 11:07:15:826 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:125)
[4/8/16 11:07:15:826 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:80)
[4/8/16 11:07:15:826 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:908)
[4/8/16 11:07:15:826 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:939)
[4/8/16 11:07:15:827 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:507)
[4/8/16 11:07:15:827 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:181)
[4/8/16 11:07:15:827 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3954)
[4/8/16 11:07:15:827 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:276)
[4/8/16 11:07:15:827 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:945)
[4/8/16 11:07:15:827 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1592)
[4/8/16 11:07:15:827 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:191)
[4/8/16 11:07:15:827 CST] 0000001b SystemErr R at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:453)
[4/8/16 11:07:15:827 CST] 0000001b SystemErr R at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:515)
[4/8/16 11:07:15:827 CST] 0000001b SystemErr R at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:306)
[4/8/16 11:07:15:827 CST] 0000001b SystemErr R at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:84)
[4/8/16 11:07:15:827 CST] 0000001b SystemErr R at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
[4/8/16 11:07:15:827 CST] 0000001b SystemErr R at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
[4/8/16 11:07:15:827 CST] 0000001b SystemErr R at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
[4/8/16 11:07:15:827 CST] 0000001b SystemErr R at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
[4/8/16 11:07:15:828 CST] 0000001b SystemErr R at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
[4/8/16 11:07:15:828 CST] 0000001b SystemErr R at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
[4/8/16 11:07:15:828 CST] 0000001b SystemErr R at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
[4/8/16 11:07:15:828 CST] 0000001b SystemErr R at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1656)
[4/8/16 11:07:15:828 CST] 0000001b SystemErr R Caused by: javax.xml.transform.TransformerException: java.io.IOException: Stream closed
[4/8/16 11:07:15:828 CST] 0000001b SystemErr R at org.apache.xalan.transformer.TransformerIdentityImpl.transform(Unknown Source)
[4/8/16 11:07:15:828 CST] 0000001b SystemErr R at org.xhtmlrenderer.resource.XMLResource$XMLResourceBuilder.createXMLResource(XMLResource.java:189)
[4/8/16 11:07:15:828 CST] 0000001b SystemErr R ... 57 more
[4/8/16 11:07:15:828 CST] 0000001b SystemErr R Caused by: java.io.IOException: Stream closed
[4/8/16 11:07:15:829 CST] 0000001b SystemErr R at java.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:134)
[4/8/16 11:07:15:829 CST] 0000001b SystemErr R at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
[4/8/16 11:07:15:829 CST] 0000001b SystemErr R at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
[4/8/16 11:07:15:829 CST] 0000001b SystemErr R at org.apache.xerces.impl.XMLEntityManager$RewindableInputStream.read(Unknown Source)
[4/8/16 11:07:15:829 CST] 0000001b SystemErr R at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
[4/8/16 11:07:15:829 CST] 0000001b SystemErr R at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
[4/8/16 11:07:15:830 CST] 0000001b SystemErr R at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
[4/8/16 11:07:15:830 CST] 0000001b SystemErr R at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
[4/8/16 11:07:15:830 CST] 0000001b SystemErr R at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
[4/8/16 11:07:15:830 CST] 0000001b SystemErr R at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
[4/8/16 11:07:15:830 CST] 0000001b SystemErr R ... 59 more
[4/8/16 11:07:15:842 CST] 0000001b SystemErr R java.lang.NullPointerException
[4/8/16 11:07:15:842 CST] 0000001b SystemErr R at org.xhtmlrenderer.layout.BoxBuilder.createRootBox(BoxBuilder.java:81)
[4/8/16 11:07:15:842 CST] 0000001b SystemErr R at org.xhtmlrenderer.pdf.ITextRenderer.layout(ITextRenderer.java:207)
[4/8/16 11:07:15:842 CST] 0000001b SystemErr R at com.topsoft.util.HtmlToPdfUtil.toPdf(HtmlToPdfUtil.java:65)
[4/8/16 11:07:15:842 CST] 0000001b SystemErr R at com.topsoft.action.register.EnterpriseRegisterAction.toPdf(EnterpriseRegisterAction.java:5725)
[4/8/16 11:07:15:842 CST] 0000001b SystemErr R at com.topsoft.action.register.EnterpriseRegisterAction.saveMail(EnterpriseRegisterAction.java:3599)
[4/8/16 11:07:15:842 CST] 0000001b SystemErr R at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[4/8/16 11:07:15:842 CST] 0000001b SystemErr R at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
[4/8/16 11:07:15:843 CST] 0000001b SystemErr R at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[4/8/16 11:07:15:843 CST] 0000001b SystemErr R at java.lang.reflect.Method.invoke(Method.java:600)
[4/8/16 11:07:15:843 CST] 0000001b SystemErr R at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
[4/8/16 11:07:15:843 CST] 0000001b SystemErr R at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
[4/8/16 11:07:15:843 CST] 0000001b SystemErr R at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
[4/8/16 11:07:15:843 CST] 0000001b SystemErr R at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
[4/8/16 11:07:15:843 CST] 0000001b SystemErr R at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
[4/8/16 11:07:15:843 CST] 0000001b SystemErr R at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
[4/8/16 11:07:15:843 CST] 0000001b SystemErr R at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
[4/8/16 11:07:15:843 CST] 0000001b SystemErr R at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
[4/8/16 11:07:15:843 CST] 0000001b SystemErr R at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
[4/8/16 11:07:15:844 CST] 0000001b SystemErr R at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
[4/8/16 11:07:15:844 CST] 0000001b SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
[4/8/16 11:07:15:844 CST] 0000001b SystemErr R at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
[4/8/16 11:07:15:844 CST] 0000001b SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
[4/8/16 11:07:15:844 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1661)
[4/8/16 11:07:15:844 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1602)
[4/8/16 11:07:15:844 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:149)
[4/8/16 11:07:15:844 CST] 0000001b SystemErr R at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:152)
[4/8/16 11:07:15:844 CST] 0000001b SystemErr R at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
[4/8/16 11:07:15:844 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
[4/8/16 11:07:15:844 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:125)
[4/8/16 11:07:15:844 CST] 0000001b SystemErr R at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
[4/8/16 11:07:15:844 CST] 0000001b SystemErr R at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
[4/8/16 11:07:15:844 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
[4/8/16 11:07:15:844 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:125)
[4/8/16 11:07:15:844 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:80)
[4/8/16 11:07:15:845 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:908)
[4/8/16 11:07:15:845 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:939)
[4/8/16 11:07:15:845 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:507)
[4/8/16 11:07:15:845 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:181)
[4/8/16 11:07:15:845 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3954)
[4/8/16 11:07:15:845 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:276)
[4/8/16 11:07:15:845 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:945)
[4/8/16 11:07:15:845 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1592)
[4/8/16 11:07:15:845 CST] 0000001b SystemErr R at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:191)
[4/8/16 11:07:15:845 CST] 0000001b SystemErr R at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:453)
[4/8/16 11:07:15:845 CST] 0000001b SystemErr R at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:515)
[4/8/16 11:07:15:845 CST] 0000001b SystemErr R at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:306)
[4/8/16 11:07:15:845 CST] 0000001b SystemErr R at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:84)
[4/8/16 11:07:15:845 CST] 0000001b SystemErr R at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
[4/8/16 11:07:15:845 CST] 0000001b SystemErr R at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
[4/8/16 11:07:15:845 CST] 0000001b SystemErr R at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
[4/8/16 11:07:15:845 CST] 0000001b SystemErr R at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
[4/8/16 11:07:15:845 CST] 0000001b SystemErr R at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
[4/8/16 11:07:15:845 CST] 0000001b SystemErr R at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
[4/8/16 11:07:15:845 CST] 0000001b SystemErr R at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
[4/8/16 11:07:15:845 CST] 0000001b SystemErr R at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1656)