Unwanted Helvetica font is using in pdf by Jasper

流过昼夜 提交于 2019-11-30 17:41:47

问题


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.name and/or net.sf.jasperreports.default.pdf.font.name properties.

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:

  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.



来源:https://stackoverflow.com/questions/8269631/unwanted-helvetica-font-is-using-in-pdf-by-jasper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!