We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Re: How to apply custom font for Document

Hi,


I’m having basically the same issue here. I’m using the code snippet in the docs but I cannot get it to work.

http://www.aspose.com/docs/display/wordsnet/How+to++Specify+True+Type+Fonts+Location

I can only get the font displaying correctly if I install it on my machine. It doesn’t look in the font repository I have specified. I’ve created a simple test solution with the issue (attached). Can you please have a look and see what is wrong.

I’m using Aspose.Words 15.10

The font Graphik_SKY-Regular.ttf doesn’t get applied.

Cheers
Glyn Jones

Hi Glyn,


Thanks for your inquiry. Please make sure that the path to the fonts folder is resolving correctly. Please use the following code for example:

var folderFontSource = new FolderFontSource(Server.MapPath("~/CustomFontRepository"), true);

<o:p></o:p>


Hope, this helps.

Best regards,

Hi Awais,


Thanks for your reply.

I tried your line in my example and the problem still exists. I have tried multiple ways of resolving the file location (including hard coding it!) and nothing works.

I’ve attached two images. One is the exported result when the font is installed locally and the other, when it is not. Can you please check against my example which result you get.

Regards
Glyn





Hi Glyn,


Thanks for your inquiry. I did not install the two font files in Windows Font folder but just replace the following line

var folderFontSource = new FolderFontSource(@"\CustomFontRepository", true);

with this one

var folderFontSource = new FolderFontSource(Server.MapPath("~/CustomFontRepository"), true);

and yet the output is correct and the code does not throw any fonts related warnings. Please see attached out.pdf.

Best regards,

Hi Awais,


I’ve tried your code. It does work when exporting to .pdf but not to .doc/docx. Is there something extra I need to do to get these formats working?

Regards


Hi Glyn,


Thanks for your inquiry. This is not an issue with Aspose.Words. When you open .doc/.docx with MS Word, this happens when the font specified by the document formatting doesn’t exist in the Windows\Fonts folder. Open the generated .doc/.docx with MS Word and then click File > Options > Advanced. In the “Show document content” section, click the “Font Substitution” button. The resulting dialog will show which fonts are unavailable and which ones are being substituted for them. Then look in the C:\Windows\Fonts folder for example to see whether the “missing” fonts are really missing.

Best regards,