Creating Themes for a Report using BIRT

0
156
3 min read

Creating themes

Using the power of stylesheets and libraries, one has the ability to apply general formatting to an entire report design using themes and reuse these among different reports. Themes provide a simple mechanism to apply a wide range of styles to an entire report design without the need to manually apply them.

The following example will move the styles that we have created in our library and will show how to apply them to our report using a theme.

  1. For each of the styles we have created, select them under the Outline tab and choose Export to Library….

    Creating Themes for a Report using BIRT

  2. Choose the ClassicCarsLibrary.rptLibrary file.
  3. All of the styles will reside under the defaultTheme themes section, so select this from the drop-down list that appears next to the Theme option.

  4. Repeat these steps for all styles we have created in Customer Orders.rptDesign.
  5. Delete all of the styles stored in the Customer Orders.rptDesign file. You will notice all the styles disappear from the report designer.
  6. In the Outline tab, under the Customer Orders.rptDesign file, select the root element titled Customer Orders.rptDesign. Right-click the element and select Refresh Library.

  7. The library should already be shared since we built the report using the library’s data source and datasets. If it is not, open the Resource Explorer, choose ClassicCarsLibrary.rptLibrary, right-click and choose Use Library.
  8. Under the Property Editor, change the Themes drop down to ClassicCarsLibrarydefaultTheme.
    Creating Themes for a Report using BIRT
  9. When we apply the theme, we will see the detail table header automatically apply the style for table-header.
  10. Apply the remaining custom styles to the two columns in the customer information section and the order detail row.

Now, we know that we can create several different themes by grouping styles together in libraries. So, when developing reports, you can create several different looks that can be applied to reports, simply by applying themes to reports with the help of libraries.

Using external CSS stylesheets

Another stylesheet feature is the ability to use external stylesheets and simply link to them. This works out very well when report documents are embedded into existing web portals by using the portals stylesheets to keep a consistent look and feel. This creates a sense of uniformity in the overall site.

Imagine that our graphics designer gives us a CSS file and asks us to design our reports around it. There are two ways one can use CSS files in BIRT:

  • Importing CSS files
  • Using CSS as a resource

In the following examples we are going to illustrate both scenarios. I have a CSS file containing six styles—five styles that are for predefined elements in reports and one style that is a custom style.

The following is the CSS stylesheet for the given report:

.page {
background-color: #FFFFFF;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
line-height: 24px;
color: #336699;
}

.table-group-footer-1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
line-height: 24px;
color: #333333;
background-color: #FFFFCC;
}

.title {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 24px;
line-height: 40px;
background-color: #99CC00;
color: #003333;
font-weight: bolder;
}

.table-header {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 20px;
background-color: #669900;
color: #FFFF33;
}

.table-footer {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
font-weight: bold;
line-height: 22px;
color: #333333;
background-color: #CCFF99;
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here