Jump to content
Changes to the Jaspersoft community edition download ×

Hebrew pdf font problem


friedman30

Recommended Posts

Hi,

I'm trying to generate a report with Hebrew fonts in it.

When running it with iReport tool, everything works great, but when running the report from a java code, I get an error message indicating that the desired pdf font is not found….

 

I can't find the FontMap for Jasper therefore I can't even try to add the desired font…

 

I know it is possible to use jasper reports with Hebrew, but for some reason I still did not find a way to do it…

 

PLS. H E L P . . . .

:side:

Post edited by: friedman30, at: 2007/01/25 15:42

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

the solution:

 

First of all, I've updated the iText jar and src files to the latest (1.4.8)

http://www.lowagie.com/iText/download.html

(the jar that came with the jasperReports download was older)

 

Then, I've added this code that adds the desired font at runtime:

 

HashMap fontMap = new HashMap();

FontKey key = new FontKey("Arial", false, false); //(String fontName, Boolean bold, Boolean italic)

PdfFont font = new PdfFont("(fontPath)\ARIAL.TTF",BaseFont.IDENTITY_H,true); //(String pdfFontName, String pdfEncoding, Boolean isPdfEmbedded)

fontMap.put(key,font);

 

JRPdfExporter exporter = new JRPdfExporter();

exporter.setParameter(JRPdfExporterParameter.CHARACTER_ENCODING, "UTF-8");

exporter.setParameter(JRPdfExporterParameter.FONT_MAP, fontMap);

 

Note that "Arial" parameter in FontKey method points to the iReport "Font Name" field (although the font added is actually "ARIAL.TTF") - so when designing the report, you have to choose "ARIAL.TTF" as "PDF Font Name" and "Arial" as "Font Name"!!! this is very important cause for some reason, at run time, Jasper engine searches for the TTF font by the key of "Arial".

 

Then, all you have to do is to set the parameters and export the report (or generate the report in any other way) I've done it this way:

 

//@ pathOfJasperFile – the compiled jasper file

//@parameters – a map with report's parameters

//@ conn – a connection to the DB

JasperPrint jasperPrint = JasperFillManager.fillReport(pathOfJasperFile, parameters, conn);

exporter.setParameter(JRPdfExporterParameter.JASPER_PRINT, jasperPrint);

//@pdfFileName – the file that jasper engine will create. (pdf file)

exporter.setParameter(JRPdfExporterParameter.OUTPUT_FILE_NAME, pdfFileName);

exporter.exportReport();

 

notes: a. you'll have to add a specific font for Bold font Italic font etc. (remember to set the FontName)

b. if, for example, you'll add a font and mark it as Bold – you have to choose "Bold" at iReport (when designing the report) or else jasper engine would not find the font that you've added, even if all other parameters are right!

 

Hope this helps.

 

Dror Friedman

alphaCSP

;)

Post edited by: friedman30, at: 2007/03/14 15:35

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...