0

我们正在使用 BIRT 3.7 api 来生成动态 PDF。我们正在使用以下逻辑设置 XML 数据源。在下面的代码片段中,我们提供 XML 字符串作为数据源。奇怪的是,自上周以来,动态数据并没有从 xml 中填充。即使在 FINEST 日志级别,它也不会抛出任何异常。由于我们尚未更新任何 jar,因此无法找出导致此功能中断的更改。生成的 PDF 没有动态值。

还有什么我可以尝试将java中的xml数据源设置为birt模板的方法。

String paramStr = readFileAsString(servletContext.getRealPath("/WEB-INF/classes")
+ "/resources/test.xml");

FileInputStream fis = new FileInputStream(servletContext.getRealPath("/WEB-INF/classes")
+ "/resources/BirtXmlDataTest.rptdesign");
IReportRunnable design = birtReportEngine.openReportDesign(fis);
DesignElementHandle designElementHandle = design.getDesignHandle();
ModuleHandle moduleHandle = designElementHandle.getModuleHandle();
ElementFactory designElementFactory = designElementHandle.getElementFactory();
OdaDataSourceHandle dataSourceHandle = designElementFactory.newOdaDataSource("Data Source",
"org.eclipse.birt.report.data.oda.xml");

moduleHandle.getDataSources().add(dataSourceHandle);

IRunAndRenderTask task = birtReportEngine
.createRunAndRenderTask(design);
PDFRenderOption options = new PDFRenderOption();
options.setSupportedImageFormats("JPG;PNG;BMP;SVG");
options.setOutputFormat(PDFRenderOption.OUTPUT_FORMAT_PDF);
options.setEmitterID(PDFRenderOption.OUTPUT_EMITTERID_PDF);
// options.setOutputStream(response.getOutputStream());
File file = new File("d:\\test" + File.separator + "file2.pdf");
FileOutputStream fos = new FileOutputStream(file);
// options.setOutputStream(response.getOutputStream());
options.setOutputStream(fos);

HashMap<String, Object> contextMap = new HashMap<String, Object>();
contextMap.put("org.eclipse.birt.report.data.oda.xml.inputStream",
new ByteArrayInputStream(paramStr.getBytes()));
contextMap.put(
"org.eclipse.birt.report.data.oda.xml.closeInputStream",
Boolean.TRUE);
task.setAppContext(contextMap);
task.setRenderOption(options);
task.run();
task.close();
4

1 回答 1

0

您在哪里为任务设置报告参数?如果您将该值称为动态值,那么这就是您所需要的:

task.setParameterValue("param_name", value);

只要遵循这个模型。否则你显然会得到一个空白报告,因为没有指定参数。

于 2013-07-10T20:38:31.530 回答