Unwanted Helvetica font is using in pdf by Jasper

2019-02-14 07:26发布

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.

2条回答
贼婆χ
2楼-- · 2019-02-14 07:37
  • The first variant is to set the default font via setting net.sf.jasperreports.default.font.name and/or net.sf.jasperreports.default.pdf.font.name properties.

For example, it were my defaults settings in iReport (dialog Options -> JasperReports Properties):

default settings

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:

set another font

And now I have Courier font in my pdf file (generated by iReport):

pdf

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.

查看更多
淡お忘
3楼-- · 2019-02-14 07:41

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:

  1. Tools -> options
  2. Under IReport, click the Fonts Tab
  3. Install a Font
  4. Click on the "Export as Extension Button" which exports it as a jar file.
  5. Add to class path.

Run report, save it, then view it.

查看更多
登录 后发表回答