Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JRProperties became deprecated, recommended way of replacing

The JRProperties class has been annotated as deprecated and replaced by JRPropertiesUtil as stated in the documentation

I've been using it to set the properties in a following way (since it was a class providing static methods),

JRProperties.setProperty("net.sf.jasperreports.default.font.name", defaultPDFFont);
JRProperties.setProperty("net.sf.jasperreports.awt.ignore.missing.font", "true");
   (...)

Which is I presume an unrecommended way of setting the properties now.


I've found two ways of doing so in compliance with API documentation, namely by directly using instance of JasperReportsContext:

JasperReportsContext jasperReportsContext = DefaultJasperReportsContext.getInstance();
jasperReportsContext.setProperty("net.sf.jasperreports.awt.ignore.missing.font", "true");
jasperReportsContext.setProperty("net.sf.jasperreports.default.font.name", defaultPDFFont);
   (...)

or by passing the JasperReportsContext instance to JRPropertiesUtil:

JasperReportsContext jasperReportsContext = DefaultJasperReportsContext.getInstance();
JRPropertiesUtil jrPropertiesUtil = JRPropertiesUtil.getInstance(jasperReportsContext);
jrPropertiesUtil.setProperty("net.sf.jasperreports.awt.ignore.missing.font", "true");
jrPropertiesUtil.setProperty("net.sf.jasperreports.default.font.name", defaultPDFFont);
   (...)

So my question is:

What is the recommended way to set properties for the Report Printer?

like image 595
mkierc Avatar asked Oct 30 '22 08:10

mkierc


1 Answers

There is no difference in your current suggest metod, but if you are looking for normal way to set properties.

The properties are loaded from .properties files and your jrxml file.

This is the override structure

  1. Loads properties from default.jasperreports.properties in the distribution

  2. Loads/override properties from jasperreports.properties if provided in root package of your distribution

  3. Loads/override property if specified in jrxml report level

    <jasperReport...>
       <property name="net.sf.jasperreports.awt.ignore.missing.font" value="true"/>
       ...
    </jasperReport>
    
  4. Loads/override property if specified in jrxml element level

    <reportElement>
         <property name="net.sf.jasperreports.export.html.class" value="test"/>
    </reportElement>
    

You can also set dynamic properties in jrxml using

<propertyExpression name="net.sf.jasperreports.export.xls.sheet.name"><![CDATA[$F{SheetName}]]></propertyExpression>

Read more to understand how to use IDE: properties-how-use-additional-properties-build-enhanced-reports

So where should you put your property net.sf.jasperreports.awt.ignore.missing.font=true?

You should not use this it will create export inconsistencies, you should use font-extensions, please see my answer on this Font is not available to the JVM with Jasper Reports

If you don't care put it in the jasperreports.properties or jrxml report level

like image 110
Petter Friberg Avatar answered Nov 15 '22 03:11

Petter Friberg