BIRT Developer Center Download

BIRT with HTML


Introduction

BIRT can be easily integrated at the HTML layer with an existing web application. This enables the HTML layer to call any BIRT functionality including invoking BIRT APIs or viewing BIRT content via the BIRT Viewer. The following sections describe how you can integrate BIRT with your application’s HTML layer.

Open-source BIRT

When deploying with the BIRT Engine, you have a couple of options to integrate at the HTML layer. The first is the BIRT Sample Viewer. You can run BIRT designs and view the output in HTML format via URL directives. To learn more about this, see the BIRT Engine and Sample Viewer deployment guide.

Another option would be to write your own Java class to get the HTML output from the BIRT Engine that you can use however you’d like:

String executeReport() throws EngineException
{
IReportEngine engine=null;
EngineConfig config = null;

try{
// start up Platform
config = new EngineConfig( );
config.setLogConfig("/logs", java.util.logging.Level.FINEST);
Platform.startup( config );

// create new Report Engine
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );

// open the report design
IReportRunnable design = null;
design = engine.openReportDesign("C:/myReport.rptdesign");

// create RunandRender Task
IRunAndRenderTask task = engine.createRunAndRenderTask(design);

// pass necessary parameters
task.setParameterValue("myParam", “myParamValue”);
task.validateParameters();

// set render options including output type
HTMLRenderOption options = new HTMLRenderOption();
ByteArrayOutputStream outs = new ByteArrayOutputStream();
options.setOutputStream(outs);
options.setImageHandler(new HTMLServerImageHandler());
options.setBaseImageURL("images");
options.setImageDirectory("C:/images");
options.setEmbeddable(true);
options.setOutputFormat("html");
task.setRenderOption(options);

// run task
String output;
task.run();
output = outs.toString();
task.close();
engine.destroy();
return output;
}catch( Exception ex){
ex.printStackTrace();
return "Error";
}
finally
{
Platform.shutdown( );
RegistryProviderFactory.releaseDefault();
}
}

This example uses an output stream to allow you to pass the HTML for use in your application. You could set it up to output to a file, as well. To learn more about the Report Engine API, see the BIRT Engine and Sample Viewer deployment guide.

JavaScript API

If you're using the BIRT Viewer Toolkit or BIRT iHub, you have access to the Actuate JavaScript API (JSAPI). This allows you to easily embed BIRT content into HTML pages with simple JavaScript.

Sample JSAPI code for embedding the Actuate Viewer into HTML:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text
/html;charset=utf-8" />
<title>Viewer Page</title>
</head>
<body onload="init( )">
<div id="viewerpane">
<script type="text/javascript" language="JavaScript"
src="http://localhost:8700/iportal/jsapi"></script>

<script type="text/javascript" language="JavaScript">

function init( ){
actuate.load("viewer");
actuate.initialize( "http://localhost:8700/iportal", null, null, null, runReport);
} function runReport( ) {
var viewer = new actuate.Viewer("viewerpane");
viewer.setReportName(“myReport.rptdesign");
viewer.submit(callback);
}
</script>
</div>
</body>
</html>

For more about the JSAPI, see either the BIRT Viewer Toolkit or BIRT iHub deployment guide.