Hindi- Bengali and Punjabi character support for Aspose Words Java

Hello,


I am trying to print characters in Hindi using Aspose Words for Java. The characters are not being printed as the input text.
The sample code snippet is below -
-------------------------------------------------------------------------------------------------------------------
import java.awt.Color;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Set;
import com.aspose.words.AutoFitBehavior;
import com.aspose.words.Cell;
import com.aspose.words.CellFormat;
import com.aspose.words.CellMerge;
import com.aspose.words.Document;
import com.aspose.words.DocumentBuilder;
import com.aspose.words.Font;
import com.aspose.words.License;
import com.aspose.words.PreferredWidth;
import com.aspose.words.Table;

public class InternationalLanguages {
public static void main(String[] args) throws Exception
{
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
CellFormat cellFormat = builder.getCellFormat();
String dataDir = “docs/Temp/”;
Table table1 = builder.startTable();
builder.insertCell();
table1.setAllowAutoFit(false);
builder.getCellFormat().setVerticalMerge(CellMerge.NONE);
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.LIGHT_GRAY);
builder.write(“Language”);
builder.insertCell();
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.WHITE);
builder.getCellFormat().setHorizontalMerge(CellMerge.FIRST);
builder.write(“हालाँकि सूर के जीवन के बारे में कई जनश्रुतियाँ प्रचलित हैं, पर इन में कितनी सच्चाई है यह कहना कठिन है। कहा जाता है उनका जन्म सन् १४७८ में दिल्ली के पास एक ग़रीब ब्राह्मीण परिवार में हुआ। जनश्रुति के अनुसार सूरदास जन्म से ही अंधे थे। आजकल थी अंधे आदमी अक्सर ‘सूरदास’ कहलाते हैं। कई लोगों ने उन्हें गुरु के रूप में अपनाया और उनकी पूजा करना शुरु कर दिया ।”);
builder.endRow();
builder.endTable();
doc.save(dataDir + “InternationalLanguages.doc”);
}
}

-------------------------------------------------------------------------------------------------------------------
This code gives desired output for languages such as English and Chinese but problems occur with languages Hindi,Punjabi and Bengali.

Also a screenshot of the final doc is attached for reference,

Please suggest a solution.

Thanks and regards,
Kautilya


Hi Kautilya,


Thanks for your inquiry. You need to format other language text with correct font. Please try using the following code for example.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
CellFormat cellFormat = builder.getCellFormat();
String dataDir = “docs/Temp/”;
Table table1 = builder.startTable();
builder.insertCell();
table1.setAllowAutoFit(false);
builder.getCellFormat().setVerticalMerge(CellMerge.NONE);
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.LIGHT_GRAY);
builder.write(“Language”);
builder.insertCell();
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.WHITE);
builder.getCellFormat().setHorizontalMerge(CellMerge.FIRST);
builder.getFont().setName(“Nirmala UI Semilight”);
builder.write(“hindi language text goes here…”);
builder.endRow();
builder.endTable();
doc.save(getMyDir() + “awjava-15.8.0.doc”);
I hope, this helps.

Best regards,
Hello Hafeez,

Thank you so much for the prompt reply. Much appreciated :)
And yes it is working perfectly fine now.

Regards,
Kautilya

Hello,


Is there any way I can set the font “Nirmala UI Semilight” as the default font for the whole documentation process?
Just to mention, I tried using-
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
FontSettings.setDefaultFontName(“Nirmala UI Semilight”);

But it doesn’t seem to work. Every time I open the document, the characters appear as empty boxes. I have to select all (Ctrl+A) contents of the document and then manually set Nirmala UI from the fonts section. This basically defeats the purpose of generating full-fledged document solely using Aspose Code.

Could you please suggest something. Please treat this as urgent.

Thanks and regards,
Kautilya

Hi Kautilya,


Thanks for your inquiry. You can try setting font of every run in document as follows:
for (Run run : (Iterable)doc.getChildNodes(NodeType.RUN, true))
run.getFont().setName(“Nirmala UI Semilight”);
Hope, this helps.

Best regards,