PHP code example of lopezsoft / jasperphp

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

    

lopezsoft / jasperphp example snippets


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

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

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

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

JasperStartet::process(
    base_path('/vendor/lopezsoft/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();

	public function generateReceipt($id) {

        $datafile = base_path('/storage/jasper/data.json');
        $output = base_path('/storage/jasper/data'); //indicate the name of the output PDF
        JasperStartet::process(
                    base_path('/resources/reports/taxinvoice80.jrxml'),
                    $output,
                    array("pdf"),
                    array("msg"=>"Tax Invoice"),
                    array("driver"=>"json", "json_query" => "data", "data_file" =>  $datafile)  
                )->execute();
     }
json
{
    "result":{
        "id":26,
        "reference":"0051711080021460005",
        "account_id":1,
        "user_id":2,
        "date":"2017-11-08 00:21:46",
        "type":"",
        "gross":138,
        "discount":0,
        "tax":4.08,
        "nett":142.08,
        "details":[
            {"id":26, "line": 1, "product_id": 26 },
        ]
    },
    "options":{
        "category":[
            {"id":3,"name":"Hair care","service":0,"user_id":1, },
        ],
        "default":{
            "id":1,"name":"I Like Hairdressing",
            "description":null,
            "address":null,
            "website":"https:\/\/www.ilikehairdressing.com",
            "contact_number":"+606 601 5889",
            "country":"MY",
            "timezone":"Asia\/Kuala_Lumpur",
            "currency":"MYR",
            "time_format":"24-hours",
            "user_id":1
        }
    }
}