Professional Documents
Culture Documents
PHP/JasperReports Integration
The purpose of this document is to explain how to implement the call of reports/ratios carried out with the JasperReports
I Introduction
PHP gained years by years an image of professional, simple and powerful language. As the French Association of the Users of
PHP in his White Paper shows it “PHP in Company” (1), there is a very great number of Internet sites of reputation, companies
of the CAC 40 which develops in PHP. What reinforces this image of robustness then. This notoriety of the language is also
visible taking into account the number of articles which is devoted to him, and numbers it very important the research carried
out on Google(2).
There are some bookshops of good level for the production of graphs, of documents to format pdf However, little of them
provide an environment to assist the originators of reports/ratios in their development and their publication. Agatha
Carryforwards (3), a Brésilien project has the ambition to bring to PHP the tools for reporting which it misses. This solution
although functional calculus does not support PHP5 to date (4). In the same way, the new platform of Zend in version 3.0.2 (5)
poster a support for BIRT(6), an environment of design of report/ratio based under Eclipse and supported by Actuate.
Jasper Reports offered to the world Java TM an engine of great quality for the generation of reports/ratios gathering tables,
graphs, mixing with the very heterogeneous data sources (report/ratio multi-source). This tool in more of being very powerful
can export towards various formats such as: pdf, HTML, xls, xml, cvs, txt, rtf and in particular a support for Open Office since
its last version. In addition, iReport, an environment of development Jasper Carryforwards gets a high level assistance in the
construction of the other reports/ratios or states. Moreover, the two projects follow a synchronized evolution. Thus, all the
functionalities added to the engine Jasper Carryforwards are taken into account by iReport.
Many are the interrogations posted on the forums on the tools for reporting in PHP, or on the integration between PHP and of
the third environment of reporting. Here is an answer: “PHP and To marble Carryforwards”! This one seems to us elegant
because it brings productivity, thanks to iReport which is rather simple to take in hand then avoiding learning the API one from
the bookshop. Then, Jasper Carryforwards is an engine now tested: many free solutions or owners embark it, of the large
companies like Siemens, the French administrations make a use of it regular. Lastly, association PHP, Java, via PHP/Java
Bridge (7) starts to gain its gallons. Even if some think that there are margins of improvement (8). This project makes possible
the instanciation of java objects since programs PHP with syntax PHP.
You included/understood it to integrate reports/ratios Jasper Carryforwards into your programs PHP it is necessary to install
PHP/Java Bridge.
The installation under GNU Linux is rather simple bus the packages are available to the format rpm. It is advisable to download
Of course it is necessary to have a virtual machine Java installed on her machine. In the file php.ini it is at least necessary to
initiate the variable java.java. You must in your file php.ini (or php.d/java.ini) add the entries:
where {Répertoire of installation JAVA} is to be replaced by the way towards your intallation of the SDK.
If you wish to make dialogue your applications PHP and a waiter J2EE to install the package php-java-bridge-tomcat:
which decompressed files there is a file Web JavaBridge.war . Also decompress and copy the files JavaBridge.jar and java-
x86-windows.dll respectively since Web-INF/lib and Web-INF/cgi in the repertory of your extension php. Lastly, you
configuration php.ini
Extension=php_java.dll
Your file php.ini integrates the preceding line then and is close to what follows:
configuration php.ini
; windows Extensions ; Note that ODBC support is built in, so no dll is nedded for it.; Note that mny DLL files are
located in the extensions/ (PHP 4) ext. (PHP 5)……;extension-php_mbstring.dll;extension-php_bz2.dll……
extension-php_java.dll……
configuration php.ini
;;;;;;;;;;;;;;;;;;; ; Module Settings ;;;;;;;;;;;;;;;;;;;;[java]java.java_home = “c:\Program
File\Java\jdk1.50_10\bin “java.java =” c:\Program File\Java\jdk1.50_10\bin\javaw.exe “java.class.path=”
c:\php\ext\JavaBridge.jar “java.library.path =” c:\php\ext “;java.hosts =”127.0.0.1:8080″;java.servlet = One
java.log_level = 2
Of course the various variables are to be initialized with the values relative to your evironnement Java (the repertory where is
You must start again your waiter apache and check that you have well the support java of PHP.
phpinfo()
<?php phpinfo();?>
Save this file, publish it on your environment Web, and call the page since your navigator. You will have to observe the support
III-B. to write the script PHP which calls your file JRXML
In the example which follows we will proceed to instanciations of the classes of the API java To marble Carryforwards while
following the stages generally indicated in the examples provided by their demonstration.
Create a file which you can for example name jasperreports.php and add the following lines:
Add the file alticJasper.jar it contains a small utility to create a connection JDBC.
You must thus modify the parameters of connections towards your data base. Also think of adding the bookshop of connector
Indicate driver JDBC of your data base, for example for MySql
Once these parameter settings finished, you are able to generate your JasperReports reports/ratios since PHP. Compilation is
undoubtedly not useful if you to directly publish the files “jasper” which you can recover since iReport.
IV. Conclusion
This small example shows how it is thus possible to exploit JasperReports via an application PHP. This integration brings to PHP
a tool for powerful and particularly productive reporting thanks to iReport. The originators of reports/ratios finds themselves in
To increase the productivity for this reason it would be interesting to encapsulate JasperReports in order to mask complexity of
it not to reject the users of PHP already accustomed to a relatively simple syntax. Let us take for example the connection
towards the data base one would need a line of code which would be:
or
The encapsulation would also avoid with developers PHP having to handle the direct calls with the classes java, which would
The Dynamic project To marble offer a simplification of API JasperReports. It would be interesting to be based on this project
Go back to publication: 01/06/2007, Date of update: 24/08/2007 By Charly Clairmont (Site perso)
To go further
Jasper Reports and PHP It is a very good article which brings already a certain abstraction of complexity To marble
Carryforward in PHP. It is necessary I think of going even further. But it is a very good beginning.
http://www.rjohnson.id.au/wordpress/2007/02/04/jasper-carryforwards-and-php/
Comments (19)
1. Agung says:
3. HK says:
8. Nisha says:
9. Integrating Jasper-Reports to PHP - sebuah posting blog jagadmaya di digg.com | Alhaniin Blog - when miss is
everything says:
May 26, 2009 at 5:29 am
[...] carried out with the Jasper-Reports format from an application PHP via bridge PHP/JAVA Bridge. read more |
digg [...]