Reputation: 529
I have designed .rptdesign file from Eclipse . It has XML Data Source. It is working fine from there. Now what I want to generate PDF file from that .rptdesign in Java application.
Can anyone guide me how to do that ?
Upvotes: 0
Views: 3948
Reputation: 139
BIRT Designer studio gives us .rptdesign files like you rightly mentioned.
However , when we need to develop reports at runtime from our java/web applications , we need :
.) reports during runtime
Its a total study with emphasize on integrating BIRT engine with java application. Refer the following link/code for a head start.
EngineConfig config = null;
try{
config = new EngineConfig( );
config.setBIRTHome("C:/birt/birt-runtime-2.3RC3/birt-runtime-2_3_0/ReportEngine");
//config.setLogConfig(null, Level.FINE);
//config.setResourcePath("C:/work/workspaces/2.3rc3srcexamples/APIs/Reports");
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
IDesignEngineFactory dfactory = (IDesignEngineFactory) Platform
.createFactoryObject( IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );
dengine = dfactory.createDesignEngine( new DesignConfig() );
IReportRunnable design = null;
//Open the report design
SessionHandle session = dengine.newSessionHandle(ULocale.ENGLISH );
// design = engine.openReportDesign("C:/Workspace_Reporting/DEAPI/src/deapi/firstTemplate.rpttemplate");
design = engine.openReportDesign("C:/designTemplate.rpttemplate");
ReportDesignHandle report = (ReportDesignHandle) design.getDesignHandle( );
println( " REPORT dataset :"+report.getDataSets());
// report.saveAs("Template1.rptdesign");
if(!(params.templateQuery).equals(null))
changeDataSet(report);
//ds_interestRateCode
//Create task to run and render the report,
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
task.setParameterValue("templateTitle",params.templateTitle);
task.validateParameters();
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFileName("C:/Reports/"+params.templateTitle);
options.setOutputFormat("html");
options.setImageDirectory("images");
task.setRenderOption(options);
task.run();
task.close();
session.closeAll(false);
engine.destroy();
Platform.shutdown();
System.out.println("Finished Generation !");
// redirect(action: index(),controller: GenericReportGeneratorController)
renderFile((params.templateTitle))
}catch( Exception ex){
ex.printStackTrace();
}
}
def renderFile(def fileName)
{
String profileImagePath = "C:/Reports/"
response.setContentType("APPLICATION/OCTET-STREAM")
//response.setContentType("text/html;charset=UTF-8")
response.setHeader("Content-Disposition", "Attachment;Filename="+(fileName))
def file = new File(profileImagePath+fileName)
def fileInputStream = new FileInputStream(file)
def outputStream = response.getOutputStream()
byte[] buffer = new byte[4096];
int len;
while ((len = fileInputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, len);
}
outputStream.flush()
outputStream.close()
fileInputStream.close()
}
https://wiki.eclipse.org/Java_-_Simple_Design_Engine_API_(BIRT)
Upvotes: 1