xdocreport无法处理模板并生成PDF

时间:2015-06-17 14:25:22

标签: java pdf xdocreport

我使用opensagres / xdocreport从odt文件生成pdf时遇到问题  图书馆。 使用NPE,process()方法调用失败。简短的研究表明,XDocReportEscapeReference.setRuntimeServices()中没有模板引擎。任何人都可以帮我理解这段代码有什么问题,可以推荐一些其他简单的库从模板生成pdf吗?

ITemplateEngine templateEngine = (ITemplateEngine) rs.getProperty( VELOCITY_TEMPLATE_ENGINE_KEY );

这是我的测试项目:

        IXDocReport template = XDocReportRegistry.getRegistry().loadReport(resource.getInputStream(), TemplateEngineKind.Velocity);
        Options options = Options.getTo(ConverterTypeTo.PDF).via(ConverterTypeVia.ODFDOM);

        IContext context = template.createContext();
        context.put("a", "test A");
        context.put("b", "test B);

        template.convert(context, options, stream);

错误消息:

fr.opensagres.xdocreport.core.XDocReportException: java.lang.NullPointerException
at fr.opensagres.xdocreport.template.velocity.internal.VelocityTemplateEngine.initializeVelocityEngine(VelocityTemplateEngine.java:136)
at fr.opensagres.xdocreport.template.velocity.internal.VelocityTemplateEngine.getVelocityEngine(VelocityTemplateEngine.java:118)
at fr.opensagres.xdocreport.template.velocity.internal.VelocityTemplateEngine.processWithCache(VelocityTemplateEngine.java:96)
at fr.opensagres.xdocreport.template.AbstractTemplateEngine.process(AbstractTemplateEngine.java:112)
at fr.opensagres.xdocreport.template.AbstractTemplateEngine.process(AbstractTemplateEngine.java:83)
at fr.opensagres.xdocreport.document.AbstractXDocReport.processTemplateEngine(AbstractXDocReport.java:775)
at fr.opensagres.xdocreport.document.AbstractXDocReport.convert(AbstractXDocReport.java:703)
at ee.maksekeskus.backoffice.services.impl.ReportServiceImpl.generateMerchantContactReport(ReportServiceImpl.java:47)
at ee.maksekeskus.backoffice.services.impl.ReportServiceImlTest.testReportGeneration(ReportServiceImlTest.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)

引起:java.lang.NullPointerException     at fr.opensagres.xdocreport.template.velocity.internal.XDocReportEscapeReference.setRuntimeServices(XDocReportEscapeReference.java:56)     在org.apache.velocity.runtime.RuntimeInstance.initializeSpecificEventHandler(RuntimeInstance.java:712)     在org.apache.velocity.runtime.RuntimeInstance.initializeEventHandlers(RuntimeInstance.java:626)     在org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:243)     在org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:534)     在org.apache.velocity.app.VelocityEngine.init(VelocityEngine.java:144)     at fr.opensagres.xdocreport.template.velocity.internal.VelocityTemplateEngine.initializeVelocityEngine

0 个答案:

没有答案