【发布时间】:2015-11-03 13:53:05
【问题描述】:
在 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);
}
}
【问题讨论】:
-
我不知道那个 API,但我猜你需要在 IXDocReport 报告之后加上一行;设置模板引擎。它可能看起来像 report.setTemplateEngine("some string");
-
是的,我使用 TemplateEngineKind.Velocity 设置引擎,您知道我可以使用的任何其他适用于 ODT 文档类型的 API 吗?
-
对不起,我从来没有使用过。这是一个建议。在以“IContext”开头的行之前,在 ~like~ System.out.println(report.getTemplate()) 中添加一行。它应该将“Velocity”返回到您的控制台日志,但如果它返回 null 或错误,那么您可以确定它没有正确设置或丢失。
标签: java pdf xpages xdocreport