0

在 Java 中使用 XDocReport 库,我想使用 odt 模板创建 odt 文档,然后将文件转换为 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); 
            } 
}
4

1 回答 1

0

您似乎希望使用 Velocity,因此您需要在类路径中添加fr.opensagres.xdocreport.template.velocity JAR,它提供了 ITemplateEngine 和 Velocity 的实现。您也需要 Velocity JAR 和她的依赖项。

于 2015-11-04T15:15:02.843 回答