Helvetica junk font used in pdf by Jasper

I have a problem that Helvetica, which I do not use in any of my JRXML fields, is used as the default font in Jasper PDF reports.

I am using iReports 4.0.2.

+4
source share
2 answers
  • 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):

default settings

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:

set another font

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

pdf

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 .

+5
source

I use NetBeans, and in one of my projects I wanted to use Garamond as my default font for my PDF files, so I did this:

  • Tools -> Options
  • In the IReport section, click the Fonts tab
  • Set font
  • Click "Export as an extension button", which exports it as a jar file.
  • Add to class path.

Run the report, save it and view.

+2
source

Source: https://habr.com/ru/post/1383063/


All Articles