PHP code example of drsoft / laraveljasper

1. Go to this page and download the library: Download drsoft/laraveljasper 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/ */

    

drsoft / laraveljasper example snippets



use LaravelJasper;
$path_reports = null
$input = __DIR__ . '/vendor/drsoft/laraveljasper/examples/hello_world.jrxml'; 

OR  

$input = 'hello_world.jrxml'; 
$path_reports = __DIR__ . '/vendor/drsoft/laraveljasper/examples/';

LaravelJasper::compile($input,'',$path_reports)->execute();



use LaravelJasper;

$path_reports = null
$input = __DIR__ . '/vendor/drsoft/laraveljasper/examples/hello_world.jasper'; 

OR  

$input = 'hello_world.jasper'; 
$path_reports = __DIR__ . '/vendor/drsoft/laraveljasper/examples/';

$output = __DIR__ . '/vendor/drsoft/laraveljasper/examples';    
$options = [ 
    'format' => ['pdf', 'rtf'] 
];


LaravelJasper::process(
    $input,
    $output,
    $options,
    $path_reports
)->execute();



use LaravelJasper;

$path_reports = null
$input = __DIR__ . '/vendor/drsoft/laraveljasper/examples/hello_world.jrxml'; 

OR  

$input = 'hello_world.jrxml'; 
$path_reports = __DIR__ . '/vendor/drsoft/laraveljasper/examples/';


$output = LaravelJasper::listParameters($input,$path_reports)->execute();

foreach($output as $parameter_description)
    print $parameter_description . '<pre>';


use LaravelJasper;    

$path_reports = null
$input = '/your_input_path/your_report.jasper'; 

OR 
$path_reports = 'your_input_path'
$input = 'your_report.jasper'; 

$output = '/your_output_path';
$connection= config('database.default');
$databaseName = config('database.connections.'.$connection);
        
            
            $options = [
                'format' => ['pdf'],
                'locale' => 'en',
                'params' => [
                    "RECORD_ID"=>1,

                ],
            
                'db_connection' => [
                    'driver' => $connection, //mysql, ....
                    'username' => $databaseName['username'],
                    'password' => $databaseName['password'],
                    'host' => $databaseName['host'],
                    'database' => $databaseName['database'],
                    'port' => $databaseName['port']
                ]
            ];


LaravelJasper::process(
        $input,
        $output,
        $options,
        $path_reports
)->execute();

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