hboie/jasper-report-bundle

Symfony 2-5 Bundle integrating the Jaspersoft REST v2 client (jaspersoft/rest-client)

v1.1 2020-02-20 21:22 UTC

This package is auto-updated.

Last update: 2020-09-23 12:17:01 UTC


README

The JasperReportBundle requires jaspersoft/rest-client and provides an JasperReport-Client as service in the Symfony service container.

Installation with Symfony 4 / 5

1 Add bundle to composer.json:

    composer require hboie/jasper_report_bundle

2 The Bundle will be registred automatically and by executing the recipe the configuration file jasper-report.yaml will be created in the config/packages directory

3 Change the standard setting in the file jasper-report.yaml

    hboie_jasper_report:
        host:      'http://localhost:8080/jasperserver'
        username:  jasperadmin
        password:  jasperadmin
        org_id:    null

e.g. you can reference the password in the .env file

    hboie_jasper_report:
        host:      'http://localhost:8080/jasperserver'
        username:  jasperadmin
        password:  '%env(resolve:JASPER_ADMIN_PASSWD)%'
        org_id:    null

Usage in Symfony 4 / 5

The bundle supports autowiring, so you can access the report-service directly in your controller, e.g.

    use Symfony\Component\HttpFoundation\Request;
    use Hboie\JasperReportBundle\ReportService;

    public function reportAction(Request $request, ReportService $reportService)
    {
        $report = $reportService->runReport('/reports/TestReport', 'pdf');

        $response = new Response($report);
        $response->headers->set('Content-type', 'application/pdf');
        $response->headers->set('Content-Disposition', 'inline; filename=Report.pdf');
        $response->headers->set('Cache-Control', 'must-revalidate');

        return $response;
    }

Installation with Symfony 2 / 3

1 Add bundle to composer.json:

    composer require hboie/jasper_report_bundle

2 Register bundle in app/AppKernel.php:

    $bundle = [
            ...
    new Hboie\JasperReportBundle\HboieJasperReportBundle(),
            ...
    ];

3 Add parameter to app/config/config.yml

    hboie_jasper_report:
        host:      "%jasper_host%"
        username:  "%jasper_user%"
        password:  "%jasper_password%"
        org_id:    "%jasper_org_id%"

4 Add a dummy configuration in app/config/paramters.yml.dist

    jasper_host: http://localhost:8080/jasperserver
    jasper_user: jasperadmin
    jasper_password: jasperadmin
    jasper_org_id:

5 Add your own configuration in app/config/paramters.yml

Usage in Symfony 2 / 3

You can now access the Client object via the Symfony service jasperreport.client:

    $client = $this->get('jasperreport.client');

or directly access the ReportService using the Symfony service jasperreport.reportservice:

    $report = $this->get('jasperreport.reportservice')->runReport('/reports/TestReport', 'pdf');

So a controller giving back a pdf-report would look like

    public function reportAction(Request $request)
    {
        $report = $this->get('jasperreport.reportservice')->runReport('/reports/TestReport', 'pdf');

        $response = new Response($report);
        $response->headers->set('Content-type', 'application/pdf');
        $response->headers->set('Content-Disposition', 'inline; filename=Report.pdf');
        $response->headers->set('Cache-Control', 'must-revalidate');

        return $response;
    }