davidecaruso/jasper-php

PHP library to execute Jasper Reports

v1.0.2 2018-02-05 16:56 UTC

This package is auto-updated.

Last update: 2024-10-26 05:51:33 UTC


README

PHP library to generate Jasper Reports.

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.

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:

{
  "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

License

Licensed under MIT.