Wednesday, January 07, 2009

Using styles from a CSS stylesheet in BIRT 2.3+

In BIRT 2.2, I would import a stylesheet and then apply the styles to my report. Unfortunately, this isn't very maintainable. Luckily Ben has found a solution to load styles from an external CSS file though there are contraints:
  • You must use BIRT 2.3+
  • Tag styling won't work-- for example, tr { color:red } will throw an error-- you have to give the style a name like .myrow { color:red }
  • The stylesheet must be in the same Eclipse project (project references are not good enough) at design time-- you can load from another location after deploying the report
  • Your style names must be all lowercase-- BIRT saves the names in your report as lower case even if they have uppercase characters and then they won't work once deployed
Here is the procedure:

  1. Upgrade Eclipse BIRT report designer to version 2.3.1
  2. If fixing an existing report, delete all currently used styles
  3. Right-click on "styles" in the outline, and choose "Use CSS file..."
  4. Choose your css file
  5. Check the box for "Include CSS file at view time" and enter
    /path/when/deployed/your.css as the URI (note: this option is missing in BIRT 2.2; if you tried to upgrade 2.2 to 2.3 read my other blog entry about how this is basically impossible)
  6. There will be some errors if your css defines styles for tag names because BIRT doesn't like that. It only accepts class names. Just ignore it.
  7. Format the report by right-clicking and applying styles from your css
  8. Deploy the report

No comments:

Labels

Blog Archive

Contributors