2

I am using i-report 5.5.0 for jasper reports. I need to export Hindi text into PDF format, but Hindi part is getting converted to ???????.

I have already used font extension but it didn't helped:

font name: "lohit Devanagari"
PDF embedded: checked
PDF encoding:Identity-H

I have also tried other Hindi fonts but nothing worked so far..

<textField>
    <reportElement x="111" y="26" width="100" height="20" uuid="5a471a16-de7b-4f55-9c9f-b01d37938b9f"/>
     <textElement>
        <font fontName="Lohit Devanagari" pdfEncoding="Identity-H" isPdfEmbedded="false"/>
    </textElement>
    <textFieldExpression><![CDATA[$F{DISTRICT_NAME}]]></textFieldExpression>
</textField>
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
Priyesh Mishra
  • 119
  • 2
  • 8
  • Did you use the [font extensions](http://jasperreports.sourceforge.net/sample.reference/fonts/index.html#fontextensions)? – Alex K Dec 15 '15 at 10:54
  • Possible duplicate: [Creating Hindi PDF using UTF-8 in JasperReport](http://stackoverflow.com/q/21532766/876298) & [Hindi Fonts in JasperReports](http://stackoverflow.com/q/23978392/876298) & [Jasper report PDF in hindi](http://stackoverflow.com/q/27819886/876298) – Alex K Dec 15 '15 at 10:57
  • @AlexK, the possible duplicates do not have answers or accepted answer, user has tried font extension, see question (probably not correctly or ttf font not able to render the uni-code), this is why I have posted an answer. – Petter Friberg Dec 15 '15 at 11:13
  • This posts contains usefull comments and answers – Alex K Dec 15 '15 at 12:14
  • Anyone found a way to resolve this? – S_S Jun 08 '17 at 10:39
  • @PriyeshMishra I tried most of what all you have mentioned, except that mine is not a Maven project so I added .jar as libs and external JAR, but neither helped solve the problem. – S_S Jun 09 '17 at 10:06

4 Answers4

2

this worked for me

IndicLigaturizer  hindi = new DevanagariLigaturizer();
String result = hindi.process(string);
1

The correct way to go is using font-extensions. pdfEncoding="Identity-H" is deprecated.

First clear this checklist to render font in pdf:

  1. Is my actual .tff supported (OpenType) and can the font actually render the character. Not all fonts render all characters in UTF-8

Once you have created correctly font extension and its not working this is probably your problem..

  1. Do I pass correct encoding to iText. In doubts (or in general) use the encoding Identity-H this is recommend for newer PDF standards and gives you the ability to mix different encoding.

Identity-H seems ok

  1. Is my font embedded so that if I share the pdf also computers not having this font can display the content.

Embed your font (otherwise if you make it work on your computer it may not work on others), note in your jrxml is isPdfEmbedded=false, remove tag and in font-extension select true or set tag to true.

Now just generate the font-extension correctly and add it to your classpath,

How to add font extensions

EDIT: After user passed font

The font Krutidev_011.TTF is not a valid ttf font it maybe because unfortunately the standard according to Apple and the standard according to Microsoft diverged (my guess your font is an apple ttf not an open type ttf).

Caused by: net.sf.jasperreports.engine.JRRuntimeException: java.awt.FontFormatException: java.nio.BufferUnderflowException
at net.sf.jasperreports.engine.fonts.SimpleFontFace.setTtf(SimpleFontFace.java:178)

I tried to download a valid ttf font Lohit Devanagari from the web and add it as font extension, fontName="Lohit Devanagari" this is my result:

fontTest

It is rendering the fonts but the result may have Ligaturizer problem, for how to solve these see for example Why is the Gujarati-Indian text not rendered correctly using Arial Unicode MS?

If you like to try this is the font-extension I used font extension jar for Lohit Devanagari, remember to set fontName="Lohit Devanagari"

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
  • my actual .tff is rendering the word correctly and when i export to other format it works well(like in HTML, ODT ,EXCEL) only PDF export is creating problem – Priyesh Mishra Dec 15 '15 at 11:38
  • Can you share the jar of your font extension? and your jrxml (or a small jrxml with text not displaying to test your font extension)? – Petter Friberg Dec 15 '15 at 12:12
  • Jar file :-http://s000.tinyupload.com/index.php?file_id=03986171897156283365 Jrxml:- <![CDATA[$F{DISTRICT_NAME_HINDI}]]> – Priyesh Mishra Dec 15 '15 at 12:19
  • @Priyesh Mishra I have edit the answer, your TTF is not valid (this depends on the fact that there exists different TTF types....), check edit – Petter Friberg Dec 15 '15 at 12:44
  • Sir, i have downloaded your jar file and set class path ,used font name = lohit devnagri this was the result :-  Error exporting print... Identity-H ExceptionConverter: java.io.UnsupportedEncodingException: Identity-H      at java.lang.StringCoding.encode(StringCoding.java:340)      at java.lang.String.getBytes(String.java:955) – Priyesh Mishra Dec 15 '15 at 12:55
  • @Priyesh Mishra The problem is probably because you already have another definition of "Lohit Devanagari" try this find out; download this font extension http://www.jdd.it/stacktrace/LohitDevanagari_EXT.jar and use fontName="Lohit Devanagari Ext", it will not work in iReport but if you set classpath your export should work. – Petter Friberg Dec 15 '15 at 13:42
  • when i used LohitDevnagri_EXT output was :- at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997)  net.sf.jasperreports.engine.util.JRFontNotFoundException: Font 'Lohit Devanagari Ext' is not available to the JVM. See the Javadoc for more details.  and PDF was not generarted – Priyesh Mishra Dec 16 '15 at 05:23
  • one more thing i want to mention that i am using DB2 as database and table column field is VARGRAPHICS .Can this cause a problem?? – Priyesh Mishra Dec 16 '15 at 05:24
  • "Font 'Lohit Devanagari‌​ Ext' is not available to the JVM", you have not added the LohitDevanagari_EXT.jar to your class path, refeering to VARGRAPHICS, test first with some simple example (to solve font problem) then move one to VARGRAPHICS, you should not write code that should write code that contain special characters, its better to use notations es. \u010c, but I think this is a secondary problem – Petter Friberg Dec 16 '15 at 10:20
  • Thanks a lot sir.i used jasper studio software and report worked fine . i think there was some problem with PDF encoding in i-report 5.5. btw problem still persists when i use my web application for report output . – Priyesh Mishra Dec 16 '15 at 13:17
  • @Priyesh Mishra Add the font extension jar in web application – Petter Friberg Dec 16 '15 at 16:23
  • added to .m2 folder and created dependency in pom.xml but not working – Priyesh Mishra Dec 17 '15 at 07:48
  • Be sure that the correct font extension jar is in classpath (or include the font .tff, fontFamilies.xml, jasperreports_extension.properties directly in your project.) – Petter Friberg Dec 17 '15 at 09:02
  • added correct font extension file in my web application still no use – Priyesh Mishra Dec 18 '15 at 08:01
  • 1
    Problem got resolved when i attached jar file as an external . Thank you so much for your help and guidance – Priyesh Mishra Dec 21 '15 at 09:27
  • @PetterFriberg could you please post the sample jrxml and jar? – S_S Jun 08 '17 at 10:52
  • @Sumit the jar I used is already in post (the links is still up), as for as example I'm not sure what you expect just set `fontName="Lohit Devanagari"` if you use that jar. – Petter Friberg Jun 08 '17 at 10:58
  • @PetterFriberg Could you take a look at what I am doing wrong possibly? https://stackoverflow.com/questions/44428641/jrxml-hindi-text-to-pdf – S_S Jun 08 '17 at 11:07
  • @Sumit I did and I saw your feedback on this answer, just wondering why, if you care to share. – Petter Friberg Jun 08 '17 at 15:56
0

I have same problem I solve it with gargi.ttf font. download here with this configuration

"gargi" => array(
        'R' => "gargi.ttf",
        'useOTL' => 0xFF,
    ),
0

Jasper Report:- You can use Arial Unicode MS for Hindi and same font jar include in java build path

Jasper Font Arial Unicode MS

Arial unicode jar exported from ireport tool import in STS

Output same as input