Search code examples
jasper-reports

How to set subreport's background same as master report


I have a problem with JasperReports.

I have a master report, in which I set the page header and footer bands, the margins and the background. Now I have multiple sub-reports. I need that in the sub-reports, the background to be the same as in master, but I can't achieve this.

If I can't do that, I will be forced to do a copy paste of margins, background and page headers and footers for every sub-report that I have.

Can this be done?

EDIT: OK, found the problem. I embedded the background image into the report, as a Base64 variable, and the image expression is:

new java.io.StringBufferInputStream( new org.w3c.tools.codec.Base64Decoder($V{BACKGROUND_IMAGE_STRING}).processString())

EDIT 2: Found the problem. For every variable must set evaluation time: none, and value expression instead of initial value expression


Solution

  • If you want to use an embedded image in the report, you must be sure that: 1. The variable holding the base64 string has "Value Expression" set instead of "Initial Value Expression" 2. Reset type set to "None", to avoid reset many times the same variable during the report generation

    Also, instead of putting the code in the question with StringBufferInputStream as Image Expression, an additional variable that instances the image once can be added, with the same parameters set as I mentioned above.

    So, this will result in: 1 image used many times through the whole process of report generation.