I am unable to see Hindi characters in my BIRT generated pdf files. The way I am trying to accomplish this is as follows:
I have added the following lines in code so that when I run my web application on Tomcat it is able to access the rptdesign file and the translation file.
EngineConfig config = new EngineConfig();
config.setResourcePath("D:/rptDesignFiles");
I have created the fontsConfg_pdf.xml so as to load the Mangal font for Hindi script. It can be downloaded from here. This fontsConfg_pdf.xml file i have placed in the same folder as the rptDesign file. And in code I have added the following lines
URL fontConfig = null;
try {
fontConfig = new URL("file:///D:/rptDesignFiles/fontsConfig_pdf.xml");
config.setFontConfig(fontConfig);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
When I generate the report I can see in logs that first it loads the fontsConfig.xml present in org.eclipse.birt.runtime-4.2.1a.jar and then it loads my custom fonsConfig_pdf.xml
But all I see is blank for my 'Name' label in the generted pdf.
I have looked through a lot of forums but unable to figure out the mistake. Could someone please guide me as to where I am going wrong. Thanks a lot !
I was able to solve this issue. So I thought I would post my solution.
The changes I made were:
Instead of associating my rptdesign file with translation_hi_IN.properties I associated my rptdesign file with translation.properties. This is the default properties file which contains the translation for my keys in my default language (English in my case). Something like:
n1=Name
I created another translation file translation_hi_IN.properties and placed it in the same folder as tanslation.properties. This contains my translation in Hindi language:
n1=\u0928\u093E\u092E
I can switch between the default language and Hindi language by setting the locale in the code according to the language selected:
PDFRenderOption pdfOptions = new PDFRenderOption(options);
// set this locale if you want to render in Hindi language. Set no locale if text needs to be rendered in default language.
pdfOptions.setOption(IPDFRenderOption.LOCALE, new Locale("hi", "IN"));
IRunAndRenderTask task = birtEngine.createRunAndRenderTask(runnable)
// set this locale if you want to render in Hindi language. Set no locale if text needs to be rendered in default language.
Locale locale = new Locale("hi", "IN");
task.setLocale(locale);
task.setRenderOption(pdfOptions);
Also modified the fontsConfig_pdf.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<font>
<font-aliases>
<mapping name="serif" font-family="Times-Roman" />
<mapping name="sans-serif" font-family="Helvetica" />
<mapping name="monospace" font-family="Courier" />
</font-aliases>
<font-encodings>
<encoding font-family="Times-Roman" encoding="Cp1252" />
<encoding font-family="Helvetica" encoding="Cp1252" />
<encoding font-family="Courier" encoding="Cp1252" />
<encoding font-family="Zapfdingbats" encoding="Cp1252" />
<encoding font-family="Symbol" encoding="Cp1252" />
<encoding font-family="STSong-Light" encoding="UniGB-UCS2-H" />
<encoding font-family="STSongStd-Light" encoding="UniGB-UCS2-H" />
<encoding font-family="MHei-Medium" encoding="UniCNS-UCS2-H" />
<encoding font-family="MSung-Light" encoding="UniCNS-UCS2-H" />
<encoding font-family="MSungStd-Light" encoding="UniCNS-UCS2-H" />
<encoding font-family="HeiseiMin-W3" encoding="UniJIS-UCS2-H" />
<encoding font-family="HeiseiKakuGo-W5" encoding="UniJIS-UCS2-H" />
<encoding font-family="KozMinPro-Regular" encoding="UniJIS-UCS2-H" />
<encoding font-family="HYGoThic-Medium" encoding="UniKS-UCS2-H" />
<encoding font-family="HYSMyeongJo-Medium" encoding="UniKS-UCS2-H" />
<encoding font-family="HYSMyeongJoStd" encoding="UniKS-UCS2-H" />
</font-encodings>
<composite-font name="all-fonts">
<font font-family="Times-Roman" catalog="Western" />
<font font-family="STSong-Light" catalog="Chinese_S" />
<font font-family="MSung-Light" catalog="Chinese_T" />
<font font-family="HeiseiKakuGo-W5" catalog="Japanese" />
<font font-family="HYGoThic-Medium" catalog="Korean" />
<font font-family="Mangal"/> <!-- Added this line for Hindi -->
</composite-font>
</font>
After making these modifications it worked ! I hope this helps.