2015-11-03 49 views
0

在Java中使用XDocReport库时,我想使用odt模板创建odt文档,然后将文件转换为pdf文件。 当过我跑我的代码,我得到了错误:XPages:如何将ODT转换为Java中的PDF文档

Error in fr.opensagres.xdocreport.document.AbstractXDocReport, line 866: fr.opensagres.xdocreport.core.XDocReportException: Null template engine. Set template engine with IXDocReport#setTemplateEngine 

我尝试这样做:

public void convertToPDF(DominoDocument document) {    
     if (document != null) { 
      try { 
       String ooFileName = "C:\\WINDOWS\\Temp\\odtFolder\\PrintFree.odt";     

       InputStream is = new FileInputStream(ooFileName); 
       IXDocReport report; 
       report = XDocReportRegistry.getRegistry().loadReport(is,TemplateEngineKind.Velocity); 
       IContext context = report.createContext();    
       context.put("Body", "HelloWorld"); 

       OutputStream out = new FileOutputStream(new File("C:\\WINDOWS\\Temp\\odtFolder\\PrintFree"+System.nanoTime()+".pdf")); 
       Options options = Options.getTo(ConverterTypeTo.PDF).via(ConverterTypeVia.ODFDOM); 
       report.process(context,options,out); 
       System.out.println("Success"); 


      } catch (XDocReportException e) { 
       System.out.println("XDocException"); 
       OpenLogItem.logError(e); 
      } 
} 
+0

我不知道那个API,但我的猜测是你在IXDocReport报告后需要一行;设置模板引擎。它可能看起来像report.setTemplateEngine(“一些字符串”); –

+0

是的,我用TemplateEngineKind.Velocity设置引擎,你知道我可以使用的任何其他API,可以使用ODT文档类型吗? –

+0

对不起,我从来没有用过。这是一个建议。在以“IContext”开头的行之前,在〜like〜System.out.println(report.getTemplate())中放置一行。它应该将“Velocity”返回到控制台日志,但如果它返回null或错误,则可以确定它没有正确设置或缺失。 –

回答

0

看来你想使用速度,所以你需要在你的classpath中FR添加.opensagres.xdocreport.template.velocity JAR,它提供了带有Velocity的ITemplateEngine的实现。你也需要Velocity JAR和她的依赖。