Home
Analytics
Report generation using Java objects
sabu22
<p>Hi all,
I am facing an issue for generating reports using java objects. Actually i require help in creating a java method whic will help me in generating reports with
java objects as an input.
I had done it previously using xmls as input to birt
The code is as follows:
public void generate(String xmlInput, String xsltInput)
throws BirtException, UnsupportedEncodingException,
TransformerException {
// open report design
this.setBirtEngine();
// open report design
design = birtEngine.openReportDesign(getClass().getClassLoader()
.getResourceAsStream(designTemplateName)); // The designTemplate is the rptdesign
// create task to run and render report
IRunAndRenderTask task = birtEngine.createRunAndRenderTask(design);
// Added for dynamic dataSource:Start
Map appContext = task.getAppContext();
String transformedApplicationXML = transform(xmlInput, xsltInput); //creating the xml source to pass in BIRT
appContext.put(
"org.eclipse.datatools.enablement.oda.xml.inputStream",
new ByteArrayInputStream(transformedApplicationXML
.getBytes("UTF-8")));
// Use closeInputStream (true) to let BIRT automatically close the
// inputStream.
appContext.put(
"org.eclipse.datatools.enablement.oda.xml.closeInputStream",
true);
// create task to run and render report
String pdfFileName = "Report" + ".pdf";
PDFRenderOption options = new PDFRenderOption();
options.setSupportedImageFormats("PNG;GIF;JPG;BMP;SWF;SVG");
options.setOutputFormat("pdf");
options.setOutputFileName(APPFOLDERPATH);
options.setOutputFileName(pdfFileName);
task.setRenderOption(options);
task.run();
task.close();
}
The above code uses xml as input to BIRT similarly i need to pass a java object to birt.
Any help is appreciated
Thanks</p>
Find more posts tagged with
Comments
mwilliams
<p>What version of BIRT are you using? BIRT 4.3+ has a POJO data source. If you're not using 4.3+, there are several devShares that are aimed at using POJOs with BIRT, using a scripted dataset.</p>
sabu22
<p>Thanx for the reply ......</p><p> </p><p>I was able to resolve this issue. I am not using birt 4.3.0 +</p><p> </p><p>Actually my issue was . I wanted to pass object to the birt report using a java application. I was able to do it by passing it in task.getappcontext(). Then i retrieved the value in my report.</p><p> </p><p> </p><p>Thanks</p>
mwilliams
<p>Ah. Yep. Glad you got it resolved. Let us know whenever you have questions.
</p>