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?
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
Loads properties from default.jasperreports.properties
in the distribution
Loads/override properties from jasperreports.properties
if provided in root package of your distribution
Loads/override property if specified in jrxml report level
<jasperReport...>
<property name="net.sf.jasperreports.awt.ignore.missing.font" value="true"/>
...
</jasperReport>
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With