问题
I have a problem that Helvetica, which I am not using in any of my JRXML fields, is being used as the default font in Jasper PDF reports.
I am using iReports 4.0.2.
回答1:
- The first variant is to set the default font via setting
net.sf.jasperreports.default.font.nameand/ornet.sf.jasperreports.default.pdf.font.nameproperties.
For example, it were my defaults settings in iReport (dialog Options -> JasperReports Properties):
With this settings (without setting default style in the template) I have the Helvetica font in my pdf generated by iReport.
After that I've changed settings in iReport like this:
And now I have Courier font in my pdf file (generated by iReport):
With JasperReports API you can set this properties with help of JRProperties.setProperty(java.lang.String key, boolean value) method.
The 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 variant is to add default style in report's template.
The 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>
More information about working with fonts you can read here.
回答2:
I use NetBeans and on one of my projects i wanted to use Garamond as my default font for my pdfs so what i did was:
- Tools -> options
- Under IReport, click the Fonts Tab
- Install a Font
- Click on the "Export as Extension Button" which exports it as a jar file.
- Add to class path.
Run report, save it, then view it.
来源:https://stackoverflow.com/questions/8269631/unwanted-helvetica-font-is-using-in-pdf-by-jasper