Use custom fonts when creating pdf using iReport

2019-01-03 07:07发布

iReport Version : 3.7.1

I approached this problem in two ways.

My first method

I am creating a pdf page in iReport and I have one of the fields (from database) set to a font Gujarati-Salarl (A font for a regional language of India).

This font is available in the font list of iReport. When I hit preview I get the desired output , with the field in the required font style.

Everything till here is fine.

But the pdf file generated still contains the same original font in English characters.

The result is same whether i call the report from the application or from a JAVA file.

After a bit of study I found this , a second method

JRProperties.setProperty("net.sf.jasperreports.default.pdf.font.name", "C:\\Gujrati-Saral-1.ttf");

This sets the font of the pdf to the ttf font provided but now the entire pdf comes in the Guarati-saral font which is not what I am looking for..

Is there a way to specifically apply this font only to that one particular field?

or

when going by the second method is there a way to not applying the font Guarati-saral to all other fields except the required one ?

4条回答
干净又极端
2楼-- · 2019-01-03 07:09

You should use the Font Extensions mechanism.

After creating the font and exporting it as a jar file you should add generated jar file to the application classpath.

a) Creating new font in iReport (via Options -> Fonts -> "Install Font" Button)

Creating the new font descriptor in iReport

b) Exporting the new font (or the existing one) as jar file in iReport (via Options -> Fonts -> "Export as extension" Button)

enter image description here

a) Creating new font in JasperReports Studio (via Window -> Preferences -> JasperStudio -> Fonts -> "Add" Button)

b) Configure your fonts

Exporting font as jar file

c) Create JAR with your fonts in it

Export Font Jar

enter image description here

You can find more information about using Font Extensions here.

查看更多
甜甜的少女心
3楼-- · 2019-01-03 07:17

For those, who need Russian language in Jasper Reports (at least in opennms of old versions), following combination does the trick without using the Font Extension:

Font Name: SanSerif PDF Font: Courier PDF Encoding: CP1251 PDF Embedded: Yes (not sure, may be it works even without)

Alexey Bakhmutov

查看更多
劳资没心,怎么记你
4楼-- · 2019-01-03 07:26

if you have problems displaying UTF-8 characters in the pdf, from version 4.8.0 of the IReport, no need to do nothing! Just change the font of the cells in the table from sanserif to Dejavu sans. thats it.

查看更多
对你真心纯属浪费
5楼-- · 2019-01-03 07:30

Select the field and go to filed properties and change the

  1. select DejaVu Sans as Font Name
  2. select Pdf Encoding to CP1256 (Arabic)
  3. select pdf font name to Courier

with these changes in I got arabic data showing in PDF.

查看更多
登录 后发表回答