2015-11-03 116 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和她的依賴。