Jasper PHP
PHP library to generate Jasper Reports., (*1)
Install
$ composer require davidecaruso/jasper-php
This automatically installs and provides the Jasper Starter executable and the MySQL Connector Driver. You can also pass to the library's constructor your jasperstarter file's path., (*2)
Requirements
- PHP >= 7.0
- Java >= 1.8.0
- Jasper Starter (automatically provided by the Composer installation)
Usage
Compile a jrxml file into a jasper file:
$jasper = new JasperPHP;
$jasper->compile('path/to/report.jrxml')->execute();
Generate report via JSON connection:
$jasper = new JasperPHP;
$jasper->process(
'path/to/report.jasper',
null,
['csv'],
[],
[
'driver' => 'json',
'json_query' => 'data',
'data_file' => 'path/to/data.json'
]
)->execute();
Example of data.json file:, (*3)
{
"data": [
{
"first-name": "Foo",
"last-name": "Bar",
"age": 32
},
{
"first-name": "Baz",
"last-name": "Foobar",
"age": 16
}
]
}
Generate report via MySQL connection:
$jasper = new JasperPHP;
$jasper->process(
'path/to/report.jasper',
false,
array('xlsx'),
array(),
array(
'driver' => 'mysql',
'username' => 'root',
'password' => 'root',
'host' => 'localhost',
'database' => 'mydatabase',
'port' => '3306',
)
)->execute();
Use an own executable Jasper Starter file:
$jasper = new JasperPHP('path/to/jasperstarter');
$jasper->compile('path/to/report.jrxml')->execute();
Author
Davide Caruso, (*4)
License
Licensed under MIT., (*5)