Package to generate reports with JasperReports 6 library through JasperStarter v3 command-line tool. More information in https://github.com/cossou/JasperPHP
composer require penblu/jasperphp
This package aims to be a solution to compile and process JasperReports (.jrxml & .jasper files).
First we need to compile our JRXML
file into a JASPER
binary file. We just have to do this one time.
Note: You don't need to do this step if you are using Jaspersoft Studio. You can compile directly within the program.
$jasper = new JasperPHP();
JasperPHP->compile(__DIR__ . '/vendor/penblu/jasperphp/examples/Blank_A4_1.jrxml')->execute();
This command will compile the hello_world.jrxml
source file to a hello_world.jasper
file.
Note: If you are using Laravel 4 run php artisan tinker
and copy & paste the command above.
Now lets process the report that we compile before:
$jasper = new JasperPHP();
$jasper->process(
base_path(__DIR__ . '/vendor/penblu/jasperphp/examples/Blank_A4_1.jasper'),
false,
array('pdf', 'xlsx'),
array('php_version' => phpversion())
)->execute();
Now check the examples folder! :) Great right? You now have 2 files, Blank_A4_1.pdf
and Blank_A4_1.xlsx
.
Check the API of the compile
and process
functions in the file vendor/penblu/jasperphp/JasperPHP.php
file.
Querying the jasper file to examine parameters available in the given jasper report file:
$jasper = new JasperPHP();
$output = $jasper->list_parameters(
base_path(__DIR__ . '/vendor/penblu/jasperphp/examples/Blank_A4_1.jasper')
)->execute();
foreach($output as $parameter_description)
echo $parameter_description;
We can also specify parameters for connecting to database:
$jasper = new JasperPHP();
$jasper->process(
base_path(__DIR__ . '/vendor/penblu/jasperphp/examples/Blank_A4_1.jasper'),
false,
array('pdf', 'xlsx'),
array('php_version' => phpversion()),
array(
'driver' => 'postgres',
'username' => 'vagrant',
'host' => 'localhost',
'database' => 'samples',
'port' => '5433',
)
)->execute();
- Java JDK 1.6 or above
- PHP exec() function
- [optional] Mysql Connector (if you want to use database)
- [optional] Jaspersoft Studio (to draw and compile your reports)