PHPackages                             ptpkp/jasper-cli-bridge - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. ptpkp/jasper-cli-bridge

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

ptpkp/jasper-cli-bridge
=======================

PHP wrapper for JasperReports CLI - compile, fill and export JasperReports using JRXML templates

v1.0.1(2mo ago)033↓50%MITPHPPHP ^8.0

Since Mar 2Pushed 2mo agoCompare

[ Source](https://github.com/PTPKP/jasper-cli-bridge)[ Packagist](https://packagist.org/packages/ptpkp/jasper-cli-bridge)[ RSS](/packages/ptpkp-jasper-cli-bridge/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

JasperReports CLI Bridge for PHP
================================

[](#jasperreports-cli-bridge-for-php)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2d96ee47b2abbba9f86888f1ddf4c33687c00ac1f600565bf7962890a60a4f43/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7074706b702f6a61737065722d636c692d6272696467652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ptpkp/jasper-cli-bridge)[![Total Downloads](https://camo.githubusercontent.com/9fb309b7998224dc9fd80fa9d44820267c4aa57e44a6250147d34be651f852e5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7074706b702f6a61737065722d636c692d6272696467652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ptpkp/jasper-cli-bridge)[![License](https://camo.githubusercontent.com/5a5d5ffe5611ae287b8d38dc870e1c38b107fdb61d02bdbe4f5a00bea2989a33/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7074706b702f6a61737065722d636c692d6272696467652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ptpkp/jasper-cli-bridge)

A PHP library that provides a lightweight bridge to JasperReports, enabling you to compile, fill, and export professional PDF reports using JRXML templates. This package includes both a Java CLI tool and a PHP wrapper for seamless integration into PHP/Laravel applications.

Features
--------

[](#features)

- 🚀 Easy integration with PHP and Laravel
- 📊 Generate PDF reports from JRXML templates
- 💾 Support for JSON data sources and database connections
- 🎨 Full JasperReports feature support (charts, subreports, barcodes, etc.)
- ⚡ Lightweight CLI bridge (no heavy JasperReports server needed)
- 🔧 Configurable and flexible
- 📦 Laravel service provider and facade included

Requirements
------------

[](#requirements)

- PHP 8.0 or higher
- Java 17 or newer
- Maven (for building the Java CLI)

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require ptpkp/jasper-cli-bridge
```

### Build the Java CLI

[](#build-the-java-cli)

After installation, you need to build the Java CLI JAR file:

```
cd vendor/ptpkp/jasper-cli-bridge
mvn clean package
```

The JAR file will be created at `vendor/ptpkp/jasper-cli-bridge/target/jasper-cli-bridge-1.0.0-jar-with-dependencies.jar`.

Usage
-----

[](#usage)

### Basic PHP Usage

[](#basic-php-usage)

```
use PTPKP\JasperCliBridge\JasperReportService;
use PTPKP\JasperCliBridge\Configuration;

// Create configuration
$config = new Configuration([
    'templates_path' => '/path/to/templates',
    'output_path' => '/path/to/output',
]);

// Create service instance
$jasper = new JasperReportService($config);

// Generate a report
$pdfPath = $jasper->generateReport(
    'invoice_template',           // Template name (or full path to .jrxml)
    'db',                          // Data source: 'db' or path to JSON file
    ['invoice_id' => 12345],      // Report parameters (optional)
    '/custom/output/path.pdf'     // Custom output path (optional)
);

echo "Report generated: {$pdfPath}";
```

### Laravel Usage

[](#laravel-usage)

#### 1. Publish Configuration

[](#1-publish-configuration)

```
php artisan vendor:publish --tag=jasper-config
```

This creates `config/jasper-cli-bridge.php`.

#### 2. Build the JAR File

[](#2-build-the-jar-file)

```
php artisan jasper:build
```

This compiles the Java CLI tool (requires Maven and Java 17+).

#### 3. Configure Environment Variables

[](#3-configure-environment-variables)

Add to your `.env` file:

```
JASPER_CLI_TEMPLATES_PATH=/path/to/your/templates
JASPER_CLI_OUTPUT_PATH=/path/to/your/reports
JASPER_CLI_JAVA_EXECUTABLE=java
```

#### 4. Use the Facade

[](#4-use-the-facade)

```
use PTPKP\JasperCliBridge\Laravel\Facade as Jasper;

// Generate a report
$pdfPath = Jasper::generateReport('invoice', 'db', [
    'invoice_id' => 12345,
    'customer_name' => 'John Doe'
]);

// Check if template exists
if (Jasper::templateExists('invoice')) {
    // Template found
}

// List all templates
$templates = Jasper::listTemplates();
```

#### 5. Use Dependency Injection

[](#5-use-dependency-injection)

```
use PTPKP\JasperCliBridge\JasperReportService;

class InvoiceController extends Controller
{
    public function generate(JasperReportService $jasper, $invoiceId)
    {
        $pdfPath = $jasper->generateReport('invoice', 'db', [
            'invoice_id' => $invoiceId
        ]);

        return response()->file($pdfPath);
    }
}
```

Configuration
-------------

[](#configuration)

### PHP Configuration

[](#php-configuration)

```
use PTPKP\JasperCliBridge\Configuration;

$config = new Configuration([
    // Path to the JAR file (null = auto-detect from vendor)
    'jar_path' => '/custom/path/to/jasper-cli-bridge.jar',

    // Path to JRXML templates directory
    'templates_path' => '/path/to/templates',

    // Path for generated reports
    'output_path' => '/path/to/output',

    // Java executable (default: 'java')
    'java_executable' => '/usr/bin/java',

    // JVM options
    'jvm_options' => ['-Xmx512m', '-Dfile.encoding=UTF-8'],

    // Execution timeout in seconds (0 = no timeout)
    'timeout' => 120,
]);
```

### Laravel Configuration

[](#laravel-configuration)

Edit `config/jasper-cli-bridge.php`:

```
return [
    'jar_path' => env('JASPER_CLI_JAR_PATH', null),
    'templates_path' => env('JASPER_CLI_TEMPLATES_PATH', storage_path('app/jasper/templates')),
    'output_path' => env('JASPER_CLI_OUTPUT_PATH', storage_path('app/jasper/reports')),
    'java_executable' => env('JASPER_CLI_JAVA_EXECUTABLE', 'java'),
    'jvm_options' => [
        // '-Xmx512m',
    ],
    'timeout' => env('JASPER_CLI_TIMEOUT', 60),
];
```

CLI Usage
---------

[](#cli-usage)

You can also use the Java CLI directly:

```
java -jar jasper-cli-bridge.jar    [params.json]
```

**Parameters:**

- ``: Path to JRXML template file
- ``: Path to JSON data file, or `db` for database connection
- ``: Destination PDF file path
- `[params.json]`: Optional JSON file with report parameters

**Examples:**

```
# Generate from JSON data
java -jar jasper-cli-bridge.jar \
    /templates/invoice.jrxml \
    /data/invoice-data.json \
    /output/invoice.pdf \
    /data/params.json

# Generate from database (requires Laravel .env)
java -jar jasper-cli-bridge.jar \
    /templates/invoice.jrxml \
    db \
    /output/invoice.pdf \
    /data/params.json
```

Directory Structure
-------------------

[](#directory-structure)

```
jasper-cli-bridge/
├── config/
│   └── jasper-cli-bridge.php   # Laravel configuration
├── src/
│   ├── Configuration.php        # Configuration class
│   ├── JasperException.php      # Exception class
│   ├── JasperReportService.php  # Main service class
│   └── Laravel/
│       ├── Facade.php           # Laravel facade
│       └── ServiceProvider.php  # Laravel service provider
├── target/                      # Built JAR files (after mvn package)
├── composer.json
├── pom.xml                      # Maven configuration
└── README.md

```

Examples
--------

[](#examples)

### Example 1: Generate Invoice PDF

[](#example-1-generate-invoice-pdf)

```
use PTPKP\JasperCliBridge\JasperReportService;
use PTPKP\JasperCliBridge\Configuration;

$config = new Configuration([
    'templates_path' => storage_path('app/reports/templates'),
    'output_path' => storage_path('app/reports/output'),
]);

$jasper = new JasperReportService($config);

$pdfPath = $jasper->generateReport('invoice', 'db', [
    'invoice_id' => 12345,
    'company_name' => 'My Company',
    'logo_path' => public_path('images/logo.png'),
]);

return response()->download($pdfPath, 'invoice.pdf')->deleteFileAfterSend();
```

### Example 2: Using JSON Data Source

[](#example-2-using-json-data-source)

```
// Create JSON data file
$data = [
    'invoice' => [
        'id' => 12345,
        'date' => '2026-03-02',
        'customer' => 'John Doe',
        'items' => [
            ['name' => 'Product A', 'qty' => 2, 'price' => 50],
            ['name' => 'Product B', 'qty' => 1, 'price' => 75],
        ]
    ]
];

$jsonPath = tempnam(sys_get_temp_dir(), 'invoice_data') . '.json';
file_put_contents($jsonPath, json_encode($data));

// Generate report
$pdfPath = $jasper->generateReport(
    'invoice',
    $jsonPath,
    ['title' => 'Invoice']
);

// Clean up
unlink($jsonPath);
```

Troubleshooting
---------------

[](#troubleshooting)

### Java Not Found

[](#java-not-found)

Make sure Java 17+ is installed and in your PATH:

```
java -version
```

Or specify the full path in configuration:

```
'java_executable' => '/usr/lib/jvm/java-17-openjdk/bin/java'
```

### Permission Issues

[](#permission-issues)

Ensure the output directory is writable:

```
chmod -R 755 storage/app/jasper
```

### JAR Not Found

[](#jar-not-found)

Build the JAR file:

```
cd vendor/ptpkp/jasper-cli-bridge
mvn clean package
```

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

Credits
-------

[](#credits)

- [PTPKP Organization](https://github.com/ptpkp)
- [All Contributors](https://github.com/ptpkp/jasper-cli-bridge/contributors)

Support
-------

[](#support)

For bugs or feature requests, please create an issue on [GitHub](https://github.com/ptpkp/jasper-cli-bridge/issues).

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance85

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

76d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c23915a079b476c6f81857f2e56667138588eb670fa5270bf7f28fca7a8999f1?d=identicon)[amin-pkp](/maintainers/amin-pkp)

---

Top Contributors

[![amin-pkp](https://avatars.githubusercontent.com/u/225359101?v=4)](https://github.com/amin-pkp "amin-pkp (2 commits)")

---

Tags

pdfreportsjasperreportsjavajasperjrxmlcli-bridge

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ptpkp-jasper-cli-bridge/health.svg)

```
[![Health](https://phpackages.com/badges/ptpkp-jasper-cli-bridge/health.svg)](https://phpackages.com/packages/ptpkp-jasper-cli-bridge)
```

###  Alternatives

[geekcom/phpjasper

A PHP report generator

493258.4k1](/packages/geekcom-phpjasper)[soluble/jasper

Jasper reports in PHP

101.1k](/packages/soluble-jasper)[quilhasoft/jasperphp

Pure PHP library to read JRXML files made with 'JasperSoft Studio' and generate reports in PDF

7542.4k1](/packages/quilhasoft-jasperphp)[robregonm/yii2-pdf

Yii 2 PDF Response Formatter

4647.5k1](/packages/robregonm-yii2-pdf)[geekcom/phpjasper-laravel

A PHP report generator

3341.9k](/packages/geekcom-phpjasper-laravel)[simitgroup/phpjasperxml

PHP PDF renderer of open source jasper report studio.

492.8k](/packages/simitgroup-phpjasperxml)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
