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>
this worked for me
IndicLigaturizer hindi = new DevanagariLigaturizer();
String result = hindi.process(string);
The correct way to go is using font-extensions. pdfEncoding="Identity-H"
is deprecated.
First clear this checklist to render font in pdf:
.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..
Identity-H seems ok
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 selecttrue
or set tag totrue
.
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:
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With