PHP code example of fazo96 / jasperphp

1. Go to this page and download the library: Download fazo96/jasperphp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fazo96 / jasperphp example snippets


JasperPHP::compile(base_path() . '/vendor/cossou/jasperphp/examples/hello_world.jrxml')->execute();

JasperPHP::process(
	base_path() . '/vendor/cossou/jasperphp/examples/hello_world.jasper',
	false,
	array("pdf", "rtf"),
	array("php_version" => phpversion())
)->execute();

$output = JasperPHP::list_parameters(
		base_path() . '/vendor/cossou/jasperphp/examples/hello_world.jasper'
	)->execute();

foreach($output as $parameter_description)
	echo $parameter_description;

JasperPHP::process(
    base_path() . '/vendor/cossou/jasperphp/examples/hello_world.jasper',
    false,
    array("pdf", "rtf"),
    array("php_version" => phpversion()),
    array(
      'driver' => 'postgres',
      'username' => 'vagrant',
      'host' => 'localhost',
      'database' => 'samples',
      'port' => '5433',
    )
  )->execute();

 
.......
.......
'providers' => [
    .......
    Illuminate\Translation\TranslationServiceProvider::class,
    Illuminate\Validation\ValidationServiceProvider::class,
    Illuminate\View\ViewServiceProvider::class,
    //insert jasper service provider here 
    JasperPHP\JasperPHPServiceProvider::class
],
......
......



namespace App\Http\Controllers;
use JasperPHP; // put here
......
......
    public function generateReport()
    {        
        //jasper ready to call
        JasperPHP::compile(base_path() . '/vendor/cossou/jasperphp/examples/hello_world.jrxml')->execute();
    }
......    

use JasperPHP\JasperPHP as JasperPHP;

Route::get('/', function () {

    $jasper = new JasperPHP;

	// Compile a JRXML to Jasper
    $jasper->compile(__DIR__ . '/../../vendor/cossou/jasperphp/examples/hello_world.jrxml')->execute();

	// Process a Jasper file to PDF and RTF (you can use directly the .jrxml)
    $jasper->process(
        __DIR__ . '/../../vendor/cossou/jasperphp/examples/hello_world.jasper',
        false,
        array("pdf", "rtf"),
        array("php_version" => "xxx")
    )->execute();

	// List the parameters from a Jasper file.
    $array = $jasper->list_parameters(
        __DIR__ . '/../../vendor/cossou/jasperphp/examples/hello_world.jasper'
    )->execute();

    return view('welcome');
});

'JasperPHP\JasperPHPServiceProvider',