Jump to content
Changes to the Jaspersoft community edition download ×

Specification of a single style across reports


Recommended Posts

Is it possible to use include files and styles with JasperReports so that colors and styles can be changed in a single place across all reports instead of being copied all over the place? something similar to cascading css used in HTML? If yes, can describe how it can be done? thanks.
Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

I got it after viewing demosamplesquery.



In textual summary, it's as follows:



1) In the jrxmls, declare the style representation as "&reportStyles;"



2)at the top of every jrxml, specify:

<!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd" [

<!ENTITY reportStyles SYSTEM "./ReportStyles.ent">




3)Create a file named ReportStyles.ent with the style specification e.g.


<style name="Arial_Normal" backcolor="#00CCCC" isDefault="true" fontName="Arial" fontSize="12" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/>

<style name="Arial_Bold" isDefault="false" fontName="Arial" fontSize="12" isBold="true" pdfFontName="Helvetica-Bold" pdfEncoding="Cp1252" isPdfEmbedded="false"/>

<style name="Arial_Italic" isDefault="false" fontName="Arial" fontSize="12" isItalic="true" pdfFontName="Helvetica-Oblique" pdfEncoding="Cp1252" isPdfEmbedded="false"/>


Link to comment
Share on other sites

But I realise that after I opened one of the jrxmls to edit in IReport & saved & then reopened in text editor, the "&reportStyles;" is gone & replaced by the content inside ReportStyles.ent i.e. all the styles are being listed out in the jrxml. This leads back to the same initial problem. Can anyone p/s suggest a better alternative way to include style so that next time, I only need to modify at a single place?
Link to comment
Share on other sites

I'm no expert on styles but this might do the trick for you...



* Create a new report

* Add a Static Text box anywhere on the report

* Apply a style to the Static Text box

* Save the file



* Edit the xml source and set the style's isDefault parameter setting to TRUE

* Save and go back to iReport



* Remove the Static Text box as it's no longer needed

* Save the file



* Open the Options-Settings menu option

* On the bottom of the dialog box you should see a field titled "Use this file as a template for new documents"

* Browse for your newly saved template file and you are done.




Of course you could add plenty of other features to your template file, like company logo and addressing details in the header or page numbering and date printed in the page footer.




Post edited by: jmurray, at: 2007/01/16 10:25

Link to comment
Share on other sites

thanks 4 e tip on e common template, will adopt tat for header & footer :)



but i still need help for the maintenance of the common Style used by multiple reports. would prfer to update only at one place, rather than opening multiple jrxmls to change common style properties.



any comments abt wat i hv done earlier, did i follow e sample app steps correctly?

Link to comment
Share on other sites

What you are after is an external stylesheet file that you can have loaded by reference (eg. <stylesheet name="c:stylesmyStyles.xml">).



This functionality doesn't appear to be provided at the moment, and as you have discovered all style definitions are statically defined within the report context.



Perhaps you could post this as a feature request for both iReports and JasperReports. It would make life a whole lot easier for everyone.

Link to comment
Share on other sites

  • 2 months later...
I agree. My reporting is almost exclusively HTML and I'd love to see something like this. I'd also like to see the JRHTMLExporter use CSS and / or single style definitions internally. I took one of my reports and did a find/replace on all the span styles and replaced them with single definitions at the top of my file and it cut the file size of the report to 52% of its original size. For a report that spits out 5MB reports, that's a pretty considerable bandwidth savings.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...