- The first option is to set the default font using the settings of
net.sf.jasperreports.default.font.name
and / or net.sf.jasperreports.default.pdf.font.name
.
For example, these were the default settings in iReport (Options → JasperReports Properties dialog box):
With these settings (without setting the default style in the template), I have the Helvetica font in my pdf created by iReport.
After that, I changed the settings in iReport as follows:
And now I have a Courier font in my pdf file (generated by iReport):
With the JasperReports API, you can set these properties using JRProperties.setProperty (java.lang.String key, boolean value) .
Sample:
JRProperties.setProperty("net.sf.jasperreports.default.pdf.font.name", defaultPDFFont); JasperReport jasperReport = JasperCompileManager.compileReport(reportSource); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params); JasperExportManager.exportReportToPdfFile(jasperPrint, outputFileName);
- Another option is to add a default style to the report template.
Example:
<jasperReport .. topMargin="20" bottomMargin="20"> <property name="ireport.zoom" value="1.0"/> <property name="ireport.x" value="0"/> <property name="ireport.y" value="0"/> <style name="Base" isDefault="true" hAlign="Center" vAlign="Middle" fontSize="10" pdfFontName="Courier" pdfEncoding="UTF8" isPdfEmbedded="false"/> <queryString>
You can read more about working with fonts here .
source share