19

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 ?

Alex K
  • 22,315
  • 19
  • 108
  • 236
Sangeet Menon
  • 9,555
  • 8
  • 40
  • 58
  • 1
    Did you use the `Font Extensions`? – Alex K Jan 24 '12 at 11:07
  • @Alex K I am not sure about how to use them... So I don't think I have used them. Would that be helpful? How can include in my files..? – Sangeet Menon Jan 24 '12 at 11:34
  • You can read this article: http://jasperforge.org/uploads/publish/jasperreportswebsite/trunk/sample.reference/fonts/index.html#fontextensions – Alex K Jan 24 '12 at 11:52
  • @Alex I added the font from Tool > Options > ireport. The pdf was outputted with the required font, but when I call the same from the JAVA class I dont get the font displayed. It prints the original font.. What would be the reason for that? – Sangeet Menon Jan 24 '12 at 13:38
  • Is it (the jar file with your font) in classpath? – Alex K Jan 24 '12 at 13:56
  • Is everything is ok when you are using iReport for exporting report to pdf? – Alex K Jan 24 '12 at 13:57
  • @AlexK no I have not added any `jar` file with font, everything is fine when exporting the pdf from ireport. How to create the jar file with the font? is there way to do that from ireport itself...? – Sangeet Menon Jan 25 '12 at 05:20
  • You can create the jar in iReport (Options -> Fonts -> Install Font) – Alex K Jan 25 '12 at 05:34
  • @AlexK I did that as metioned in an earlier comment, that made the exported pdf from ireport have the font i required, but I want to get it run from the java file for that where would the jar file be created after the above process? – Sangeet Menon Jan 25 '12 at 06:08
  • You can create the jar file with font with help of iReport. After that you should add this jar to classpath – Alex K Jan 25 '12 at 06:16
  • @AlexK Ok...Done...Thanks a lot... Post this as an answer so that it could be helpful to others!!! – Sangeet Menon Jan 25 '12 at 06:58
  • Welcome )) I've just posted the answer – Alex K Jan 25 '12 at 07:13

4 Answers4

27

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.

Nicholas DiPiazza
  • 10,029
  • 11
  • 83
  • 152
Alex K
  • 22,315
  • 19
  • 108
  • 236
  • i screwed up the edit mixed around links a bit. can you fix it? it is attempting to be more modern by having screenshots for jaspersoft studio – Nicholas DiPiazza Dec 09 '14 at 22:56
  • The original question was about using *iReport* :). I have [also an answer](http://stackoverflow.com/a/19234053/876298) about using fonts in *Jaspersoft Stuido* – Alex K Dec 10 '14 at 08:36
  • Mac version doesnt have this option -> fonts option. How do i get around this? – L-Samuels Oct 14 '16 at 15:37
  • Looks like a bug. Sorry, I have not Mac to check. Did you try to use *JSS* (Jaspersoft Studio)? – Alex K Oct 14 '16 at 20:14
0

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.

Rodniko
  • 4,926
  • 20
  • 69
  • 93
0

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

-1

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.

Kiki
  • 2,243
  • 5
  • 30
  • 43