Click here to Skip to main content
15,392,209 members
Articles / Programming Languages / PHP
Posted 24 Aug 2011

Tagged as


9 bookmarked

Integrating BIRT reports with PHP Web sites

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
1 Sep 2011CPOL4 min read
How to consume reports created on BIRT via PHP



Considering the nowadays difficulties during the crysis, and given the evolution of open source programming languages, techniques and tools, it is important to start considering these options when choosing the technology for a given solution. 

This article introduces Eclipse BIRT and explains how you can integrate its reports with a PHP web site, so you can work it out easily and no cost.


Eclipse BIRT - Business Intelligence and Reporting Tools (BIRT) is a reporting system that you can integrate with the well known Eclipse IDE. You can generate several solutions, however on this article the focus is using the produced reports on PHP web sites (a common requirement that usually is made using other technologies). If you are aware of other technologies such as Microsoft SQL Reporting Services, you'll find this tool very simple and straight forward. 

More about BIRT:

As sometimes happens, you want to call a report on a web site. If you had ever use a RDLC file on an ASP.Net web site, or a Crystal Reports report, here we want to do the same, however, this requires some skills and specific sequence of actions to make it work.

In the first place, I made this article using XAMPP, which wraps Apache and MySql (as well as other servers) in an easy way that you can start and stop whenever you like. You can do this without it, however I highly recommend this tool. Download at: 

This seems to be a very simple approach, however it's not! There are two main challenges here:

a) Follow a very specific list of steps to make things work (install programs, SDK, configurations...)

b) Since BIRT runs on Java and you want to consume it in PHP, there must be something to make them "talk" with each other. Here enters PHP JavaBridge, which connects a native script language such as PHP or Python to a Java service such as Tomcat. This will be our translator.

The first step is to assemble your environment. Here you will install some software, SDK, make configurations, copy and paste folders... This might take a few hours to make it right.

1. Pre-requirements
1.1. Java runtime and SDK

2. Software to Install
2.1. You need to activate Tomcat. XAMPP contains it out of the box installed, however, before starting, set the environment variable
JAVA_HOME on your Windows XP to the java SDK directory. This requires restart to the machine. After that, go to <Xampp folder>\tomcat and press Catalina_start.bat to start tomcat
2.2. Download PHP/Java bridge (At: - version "Documentation". Paste JavaBridge.war file at <Xampp folder>\tomcat\webapps ahd check installation at
2.3. Install Commons Logging (Download at: - Binaries, Copy .jar files into <Xampp folder>\tomcat\webapps\birt-viewer\WEB-INF\lib\
2.4. Install BIRT Runtime (Download at: where says "Latest BIRT runtime Release Build") - copy WebViewerExample folder to <Xampp Folder>\tomcat\webapps\ and rename it to Birt-Viewer.
2.5. Start Apache at XAMPP;
2.6. Start Tomcat at<Xampp Folder>, executing catalina_start.bat
2.7. Test tomcat: http://localhost:8080/ (if something saying tomcat shows, it's ok)
2.8. Test JavaBridge: http://localhost:8080/JavaBridge (if something saying javabridge shows, it's ok)


At this point you should have the environment working, with both BirtViewer and JavaBridge installed and running. Now you're ready to use the PHP code.

Using the code

There are two ways to consume the code - one via Birt Viewer, other directly via JavaBridge. Via Birt Viewer you consume the report via http, and the result is the report and the options to print, export...however you must be aware of security concerns since you will have to be able to access the URL of the report from the web. Via Javabridge, you access the file directly (not via http), so what is rendered is simple HTML. However, you don't have the print and export options...


Now just create a new web site on Apache (not on tomcat). Remember to have tomcat service started!!

Calling via Birt Viewer, I've used the TopNPercent report that BirtViewer brings out of the box:

   //	1. Http request
  $fname = "TopNPercent.rptdesign"; // name of the report
  $topCount = 5;	//	Top Count parameter
  $topPercentage = 25;	//	Top Percentage parameter
  // Redirect browser
  $dest = "http://localhost:8081/birt-viewer/frameset?__report=";
  $dest .= urlencode( realpath( $fname ) );
  $dest .= "&Top Count=" . urlencode( $topCount );
  $dest .= "&Top Percentage=" . urlencode( $topPercentage );
  header("location: ".$dest);


Calling via JavaBridge directly, using the same report:


  //	2.	Local file using BIRT runtime engine
  if (!(get_cfg_var('java.web_inf_dir'))) {
    define ("JAVA_HOSTS", "");
    define ("JAVA_SERVLET", "../../tomcat/webapps/JavaBridge/JavaBridge.phpjavabridge");
  $pth = "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"];
  $path_parts = pathinfo($pth);
  $imageURLPrefix = $path_parts['dirname'] ."/images/";

  $here = getcwd();

  $ctx = java_context()->getServletContext();
  $birtReportEngine =        java("org.eclipse.birt.php.birtengine.BirtEngine")->getBirtEngine($ctx);

        $report = $birtReportEngine->openReportDesign("${here}/TopNPercent.rptdesign");
        $task = $birtReportEngine->createRunAndRenderTask($report);
        $task->setParameterValue("Top Count", new java("java.lang.Integer", 6));
	$task->setParameterValue("Top Count", new java("java.lang.Integer", 6));

	$taskOptions = new java("");
	$outputStream = new java("");
	$ih = new java( "");
	$taskOptions->setBaseImageURL($imageURLPrefix . session_id());
	$taskOptions->setImageDirectory($here . "/images/" . session_id());
	$task->setRenderOption( $taskOptions );
	$task->close();  } catch (JavaException $e) {
	echo $e; //"Error Calling BIRT";			
  }    echo $outputStream;

Points of Interest

The problem here is assemble everything. It's very easy, without a guiding line, to install it wrong. The above steps took me more than one week and googling a lot (really a lot) but seems to me that they will save you a lot of trouble and time (so I hope).

As a 5 year experience consultant using Microsoft technologies, I find myself working with these solutions without many problems. The "first time" takes longer, but after having things assembled, is as easy as other technologies.

Try this out, it's worth. If you want to make the same with less money, here is your answer.


NOTE: if you want to integrate BIRT with MySql, there is no driver installed. Follow these instructions:




This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior)
Portugal Portugal
No Biography provided

Comments and Discussions

GeneralMy vote of 5 Pin
simemon28-Aug-13 23:40
Membersimemon28-Aug-13 23:40 
Questionhosting solution Pin
vivek modi30-Jan-13 20:57
Membervivek modi30-Jan-13 20:57 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey23-Feb-12 19:37
professionalManoj Kumar Choubey23-Feb-12 19:37 
QuestionAdditional Links Pin
Jason Weathersby24-Aug-11 13:41
MemberJason Weathersby24-Aug-11 13:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.