Creating a custom template with Jaspersoft Studio

Create the Structure

Creating template is nothing more than a standard report where some elements have a precise and fixed name that is used by the Jaspersoft Studio engine to understand where to place every element.

The First thing is to create new report from File -> New -> Jasper Report. We can start with blank report or selecting one of the other templates as a starting point.

Now Design the template as par your requirement .Creating the template is same as that of generating the report.

I have created like this

Report Template

Now switch to the Preview mode and look if the result is what you want and if it is allright you can continue with the export operation.

Export the Template

To start the export wizard select click File -> Export as Report Template.

In the first dialog you will see all the resources that will be exported. Between these resources you can fine the template and other files used by it, in our example you will see the one image. In this step you will need also to select the destination folder, where the template and all his resources will be placed.

Template Export

When you have finished press Next.

Here you can define the categories where your template will be visible inside the New Report Wizard.  You can select any number of categories or your own category. To define a custom category you need only to type its name inside the text area on the bottom and press the Add button. Then your category will be added to Selected Categories list. Then your category will be added to Selected Categories list.

At this point you need to select the correct type of report, for example if it is a Tabular Report or a standard one.
Template Type and Categories

At this point you can see two different steps:

  • The first one, and the one that should appear follwoing this tutorial, is a congratulations step. It means that the template you designed is valid for the report type you have selected in the previous step.
  • The second one is a list of error messages if the template you designed is not valid for the selected type because of some design errors. For example for a template with Tabular type is expected a table in the summary band. If this table is not found it’s probably a design error. In this step all the design errors found are listed so you can look to what is wrong and fix it.

5(30)
 

OR

 
6(22)

 

In both the cases we can export the template and all resources by clicking the finish button.

In second case may your template should not work while generating the report.

Add the Templates location to Studio

  1. Now you have to put your custom template for studio.
  2. Navigate to Windows ->Preferences. A new Preferences window open.
  3. From the Left panel expand the category Jaspersoft Studio and select Template Locations.
  4. Click on New and browse the folder where you have saved template jrxml file.

Refer the screenshot below:
5(14)

Test the new template

  1. Open Jaspersoft studio.
  2. Navigate to File > New > Jasper Report.

A new Report wizard will open.
Template

  1. Select the template that you have added. Then Report will open as shown below:

Report Template
 
-By
Nitin Uttarwar
Helical It Solution

Leave a Reply