JasperReportBundle
The JasperReportBundle requires jaspersoft/rest-client and provides an JasperReport-Client as service in the Symfony service container., (*1)
Installation with Symfony Flex (4 / 5)
Basic Usage in Symfony 4 / 5
Installation with Symfony 2 / 3
Basic Usage in Symfony 2 / 3
Search Resource Command
Export Resource Command
Import Resource Command
Copying Resources between different Servers
Additional Configuration Options
, (*2)
Installation with Symfony Flex (4 / 5)
1 Add bundle to composer.json
:, (*3)
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 and the corresponding entries
in the .env
file will be made, (*4)
3 Change the standard setting in the file jasper-report.yaml
, (*5)
hboie_jasper_report:
host: 'http://localhost:8080/jasperserver'
username: '%env(HBOIE_JASPER_REPORT_USERNAME)%'
password: '%env(HBOIE_JASPER_REPORT_PASSWORD)%'
org_id: '%env(HBOIE_JASPER_REPORT_ORGID)%'
and in the .env
file, (*6)
HBOIE_JASPER_REPORT_USERNAME=jasperadmin
HBOIE_JASPER_REPORT_PASSWORD=jasperadmin
HBOIE_JASPER_REPORT_ORGID=
Basic Usage in Symfony 4 / 5
The bundle supports autowiring, so you can access the report-service directly in your controller, e.g., (*7)
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
:, (*8)
composer require hboie/jasper_report_bundle
2 Register bundle in app/AppKernel.php
:, (*9)
$bundle = [
...
new Hboie\JasperReportBundle\HboieJasperReportBundle(),
...
];
3 Add parameter to app/config/config.yml
, (*10)
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
, (*11)
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
, (*12)
Basic Usage in Symfony 2 / 3
You can now access the Client
object via the Symfony service jasperreport.client
:, (*13)
$client = $this->get('jasperreport.client');
or directly access the ReportService
using the Symfony service jasperreport.reportservice
:, (*14)
$report = $this->get('jasperreport.reportservice')->runReport('/reports/TestReport', 'pdf');
So a controller giving back a pdf-report would look like, (*15)
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;
}
Search Resource Command
With the jasper:repository:search
you can search resources on the JaserReport server, (*16)
php bin/console jasper:repository:search <Citeria> <Detail>
Criteria: search criteria
Detail: show details (optional)
If no detail-value is given, only the uri of the resources will be listed. If an detail value greater
than 0 is given, full data will be displayed., (*17)
Export Resource Command
With the jasper:export:resource
command, a given resource will be exported
from the JasperServer and downloaded to an zip-archive file., (*18)
php bin/console jasper:export:resource <UriOfResource> <Filename> <SkipDependentResources>
UriOfResource: uri of the resouce that should be downloaded
Filename: filename of the local target file
SkipDependentResources: if set to "true", dependent resource, e.g. the database
connection of a report will be skipped.
, (*19)
Import Resource Command
With the jasper:import:resource
command, a previously exported resource
can be imported to a JasperServer., (*20)
php bin/console jasper:import:resource <Filename> <IncludebrokenDependencies>
Filename: filename of the local import file
IncludebrokenDependencies: if set to "true", for resources with broken dependencies
(e.g. exported with the option SkipDependentResources
) the import process
attempts to import the resource by resolving dependencies with local resources.
, (*21)
Copying Resources between different Servers
You can use the export and import resources commands to copy resources from
one server to another, e.g. between different stages of
an application. Use the SkipDependentResources
option when exporting a
resource and the IncludebrokenDependencies
option when importing it
on the second server to avoid that the database connection is overwritten on
the target server., (*22)
Take care that the export and import keys on both servers are adjusted.
Read https://community.jaspersoft.com/documentation/tibco-jasperreports-server-security-guide/v7/using-custom-keys
for further information on how to use customs keys., (*23)
Create key store, (*24)
keytool -genseckey -keystore ./mystore -storetype jceks -storepass <storepass> -keyalg AES -keysize 128 -alias importExportEncSecret -keypass <keypass>
Copy store to JasperServer's buildomatic directory, (*25)
cp ./mystore /opt/jasperreports-server-cp-7.8.0/buildomatic/
Go to the buildomatic directory as root user and import key to JasperServer, (*26)
./js-import.sh --input-key --keystore ./mystore --storepass <storepass> --keyalias importExportEncSecret --keypass <keypass>
Restart the JasperServer application or reboot the server, (*27)
Additional Configuration Options
hboie_jasper_report:
host: 'http://localhost:8080/jasperserver'
username: '%env(HBOIE_JASPER_REPORT_USERNAME)%'
password: '%env(HBOIE_JASPER_REPORT_PASSWORD)%'
org_id: '%env(HBOIE_JASPER_REPORT_ORGID)%'
timeout: 50
timeout: timeout for REST-request (in seconds), (*28)