JasperReports with PHP Example step by step using iReport

Original Post/ Curtsy: http://chathurangat.blogspot.com/2012/03/jasperreports-with-php.html

JasperReports with PHP

Today i am going to write this article on the use of JasperReports in PHP as a reporting tool. Here i have used IReport-4.5.0 IDE for designing the JasperReport Template (known as jrxml file).In addition, you require a PHP library(third party) that generates PDF reports from the given jrxml document. this library can be downloaded from the following Git Repository
or else you can downloaded through following link

In order to design the template, please follow the steps given below.

1. load the IReport Designer tool
(executable file is available inside the bin directory)

2.after loading the IReport Tool,select new report template to start the report designing.
(File -> New)
then you will get a new window with a list of available report templates. select a template out of the available templates. in my case i have selected the Blank A4 template. please refer below.

then click the Launch Report Wizard to load the selected report template.

3. then give a Report Name and browse a Location where the report file (jrxml file) should be saved.  Please refer below.

4. then click on Next to proceed with next phase. please refer below.

As you can see in the Screen-shot, you will be displayed a list of available data source connections that can be used in your report. if you wish to create a new data source connection, you are free to do so by clicking New button.

5. if you click the New button to create new data source, you will be shown the below screen to select the the data source type. ( the data source type should be selected based on the application requirements. ) since this is PHP based web application, i have selected Database JDBC Connection as the data source type.

6. once you select the data source, click on next to proceed with next step. next will be the below screen.
here you have to provide the JDBC connection details.
 Name : just give any name for this connection for later reference  identification purpose
JDBC Driver:  select the most suitable JDBC driver from the given list based on your database. since i am using MySQL server database, i have selected  MySQL-JDBC Driver.
JDBC URL: make sure to edit the jdbc url based on your sever and database name. the default value of the jdbc url does not change, based on the value you provided for server and database. therefore please edit it manually.
Server Address : IP Address of the database sever. if the database is in your local machine, use localhost as IP.
Database : Database name that you are going to connect.
username: Username of the database server.
password : Password of the database server.
after filling all the configuration details, you can test the database conncetion by clicking the Test button provided. sometimes it may ask you to re-enter the database password. if the connection is successful, you will get a successful message as follows. then you can Save your new data source connection.
 7. then you can use your newly created data source for designing the query for your report. select the newly created data source and press Design Query button. then you will get the below window for designing the Query.
you will see a list of tables available in the connected database. you can Drag and Drop these tables to the provided area for designing the Query. then customize the columns displayed in the report by using the check boxes provided for each column.

8. once the Query is designed, press OK to finish it. the click Next to proceed with next phase. then next step is to select the required fields for your report out of the available all resulted columns of the Query you designed. add and remove the required database columns for your report with the provided button. please refer the below screen shot.

9. after completing the above operation, you can press Next button for continue with next phase. next phase is for applying the Group By clause for the report view. then phase is optional and you can skip this step by clicking just Next button. then the initial process of the report design is finished and you will be notified with the below screen. jut click on finish button.

10. then it will load and display the created .jrxml file. you are required to remember that this is the file that contains your report template. you can design the report as you wish by providing preferable title, footer and other required fileds.

11. the designing utilities are available in the Report Inspector window. please refer below screen shot.

as you can see that the selected database column fields are available under the Fields. you can drag and drop the database fields in into the Detail1 Section of your Report.Once you drag a database field, its column header section will be automatically visible underColumn Header section. In addition, the data field is visible under the Detail 1 Section. you can edit the column name as you wish.

12. Once the Design is done, you can preview the design using the Preview button.

13. The Report design elements are available in the palette window. you can get the palette window Window -> Palette

14. Once all the design is done, the it is time to integrate with your PHP application. make sure to download and import the PhpJasperLibrary in your PHP script. (copy both.jasper and .jrxml files into a same directory and give the reference in the PHP script)

//Import the PhpJasperLibrary
//database connection details
//display errors should be off in the php.ini file
ini_set('display_errors', 0);
//setting the path to the created jrxml file
$xml=  simplexml_load_file("report/chathuReport.jrxml");
$PHPJasperXML= newPHPJasperXML();
$PHPJasperXML->outpage("I");    //page output method I:standard output  D:Download file

access the report_view.php file in your LAMP/WAMP server. yo will get the report in PDF format.

Hope this will helpful for you!

Thanks and Regards,

Md. Nazim Uddin
Original Post: http://www.webprogrammingtips.com/index.php/tag/jasper-reportsexample-step-by-step-using-ireport/

Jasper reports:Example step by step using iReport

JasperReports(iReport) run with PHP & Database Oracle

August 2015    Jasper, ORACLE, PHP, XML

You can run iReport in your Oracle based PHP Application

1.      PHP Jasper Library (No required Jasper Report Server)

2.      PHP JAVA Bridge

3.      Web Service(Required Jasper Report Server)

Now I describe how to run iReports with your Oracle Based PHP Application using PHP Jasper Library

1.      Download PHP Jasper Library

2.      Create a Report folder in your application

3.      Unzip it  into Report Folder

4.      Create a Sample iReport which fetch data from Oracle Database

5.      Create DSN to connect Oracle Using ODBC( No required DSN if DB is Mysql

Show Video for How to create DSN to connect Oracle Database using ODBC

6.      Create a report_view.php page with following Script


//Import the PhpJasperLibrary



//database connection details





$version=”0.8b”;// User for Mysql



//display errors should be off in the php.ini file

ini_set(‘display_errors’, 0);

//setting the path to the created jrxml file

$xml =  simplexml_load_file(“report/sampleReport.jrxml”);

$PHPJasperXML = new PHPJasperXML();





//$PHPJasperXML->transferDBtoArray($server,$user,$pass,$db);// Mysql Default



// For using Oracle , DSN create  First


$PHPJasperXML->outpage(“I”);    //page output method I:standard output  D:Download file


access the report_view.php file in your LAMP/WAMP server. yo will get the report in PDF format.


2 thoughts on “JasperReports with PHP Example step by step using iReport

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s