Publishing a Report Template

This section describes functionality that can be restricted by the software license for Jaspersoft Studio. If you don’t see some of the options described in this section, your license may prohibit you from using them. To find out what you're licensed to use, or to upgrade your license, contact Jaspersoft.

You can add custom report templates to your JasperReports Server instance by uploading a JRXML file to a Templates directory. In addition to font and color choice, reports templates can contain images such as logos. In a template, the absolute path of image is in the repository and cannot be overwritten. Users can apply your template by selecting Custom Report Template when they create a report from an Ad Hoc View.

Creating a Report Template based on a Template in the Server

When creating a template it is easiest to start with an existing template in JasperReports Server and change the values for the properties you want (such as colors, fonts, and logos) in Jaspersoft Studio. Then, publish the new template to the server. This example shows how to change the font for a chart title.

To create a template:

1. From Jaspersoft Studio, connect to JasperReports Server as superuser.
2. In the Repository Explorer, navigate to the Public/Templates directory.

Accessing the Templates directory from Jaspersoft Studio

3. Right-click A4 Landscape in and choose Open in Editor.

Default A4 landscape template

The document will look empty, but if you click the Source tab, you see that attributes are set at the JRXML level. Note the attributes for ChartTitle:

<style name="ChartTitle" forecolor="#000000" fontName="DejaVu Sans" fontSize="12" isBold="true"/>

You can edit styles directly on the Source tab if you choose.

4. Click the Design tab, and in the Outline view, click the arrow next to Styles.
5. Click ChartTitle.

Style tab in Properties View

The styles open in the Properties tab.

6. Make these changes: 
a. Font: Century Gothic, 14 pt, bold, italic.
b. Change the forecolor to red (Click Appearance for that change.)
c. Alignment: Center

You can link to an image in your template by uploading the image to the repository and then dragging it into the appropriate band in the template. The template uses the absolute path to the image in the repository and the image cannot be changed or overwritten.

To save and publish a template:

1. Save the template with a new name.
2. A pop-up will ask if you want to publish the report to JasperReports Server. Click Yes.

Report Publishing wizard

The Report Publishing wizard appears.

3. Select the folder in which you want to store your template, and click Next.

A pop-up will appear letting you know that the template has been published successfully.

Report Template Styles in Jaspersoft Studio

When you view a report template in Jaspersoft Studio, you see it includes styles, which inherit attributes from other styles or from a default value. When you open one of the default templates in Jaspersoft Studio, you can see the available styles listed in the Outline view. When a report template is applied to a report that includes a basic chart, only the ChartTitle style is applied to the chart. In general, report styles control the general look of the report, while chart themes control the look of basic charts (implemented through JFreeCharts). For more information on chart themes, see Chart Themes.

The Inheritance tab in the Properties view shows you which styles are inherited and from where. That makes it easy if you want to change a style at a higher level, or have an attribute inherited by more styles.

Inheritance tab