Free Support Forum - aspose.com

Force font linking through code

I am currently using Aspose.Words to create a custom Microsoft Word document (in java) that needs to support various character sets but am having trouble with Font Linking.

For instance, copying the string “<span style=“font-size:10.0pt;mso-bidi-font-size:12.0pt;
font-family:“Microsoft Sans Serif”,“sans-serif”;mso-fareast-font-family:“Microsoft Sans Serif”;
mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>ꀍ༖༗༘ث” into Word 2007 manually displays the characters correctly no matter what font you currently have set. If you look at each individual character you will see that Word figured out the current font couldn’t display the typed character and picked a font that could.


The process described in the above paragraph isn’t happening when setting the font in aspose. When you create the Word document through code and open it you will notice that all the characters are set to the font you specified even if the font can’t display that character.

Is there anyway through aspose to trigger this font linking? If not then are there any utility methods to help with manually font linking in aspose?

Hi Daniel,


Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word do. In your case, you just need to specify the locale so that Microsoft Word recognizes the text according to locale. I suggest you to read following documentation link.
http://www.aspose.com/docs/display/wordsjava/Font

Please check the following code examples for your kind reference and let us know if you have any more queries.

<span lang=“EN-GB” style=“font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:green;mso-font-kerning:0pt;mso-fareast-language:PL”>// use of <span lang=“EN-GB” style=“font-size:10.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:green;mso-font-kerning:0pt;mso-fareast-language:PL”>getLocaleId/setLocaleId


<span lang=“EN-GB” style=“font-size:10.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:green;mso-font-kerning:0pt;
mso-fareast-language:PL”>// Create a run of text that contains Russian text.<o:p></o:p>

Run run = new Run(doc, "Привет");

// Specify the locale so Microsoft Word recognizes this text as Russian.

// For the list of locale identifiers see http://www.microsoft.com/globaldev/reference/lcid-all.mspx

run.getFont().setLocaleId(1049);

// use of getLocaleIdBi/setLocaleIdBi
DocumentBuilder builder = new DocumentBuilder();

// Signal to Microsoft Word that this run of text contains right-to-left text.

builder.getFont().setBidi(true);

// Specify the font and font size to be used for the right-to-left text.

builder.getFont().setNameBi("Andalus");

builder.getFont().setSizeBi(48);

// Specify that the right-to-left text in this run is bold and italic.

builder.getFont().setItalicBi(true);

builder.getFont().setBoldBi(true);

// Specify the locale so Microsoft Word recognizes this text as Arabic - Saudi Arabia.

// For the list of locale identifiers seehttp://www.microsoft.com/globaldev/reference/lcid-all.mspx

builder.getFont().setLocaleIdBi(1025);

// Insert some Arabic text.

builder.writeln("مرحبًا");

builder.getDocument().save(getMyDir() + "Font.Bidi Out.doc");


// use of
getLocaleIdFarEast/setLocaleIdFarEast

DocumentBuilder builder = new DocumentBuilder();

builder.getFont().setSize(48);

// Specify the font name. Make sure it the font has the glyphs that you want to display.

builder.getFont().setNameFarEast("SimSun");

// Specify the locale so Microsoft Word recognizes this text as Chinese.

// For the list of locale identifiers see http://www.microsoft.com/globaldev/reference/lcid-all.mspx

builder.getFont().setLocaleIdFarEast(2052);

// Insert some Chinese text.

builder.writeln("你好世界");

builder.getDocument().save(getMyDir() + "Font.FarEast Out.doc");