How can i set external font in drawstring method?

Hello Team,

We want to set “Proxima-Nova” font in drawstring method of Graphics class. How can we do that? For you reference, we want to set Proxima-Nove instead of Times New Roman. We are using Aspose.Imaging version 21.4.0. Please suggest.

RectangleF titleRect = new RectangleF(24, 90, 600, 68);
graphics.DrawString(item.Title, new Font(“Times New Roman”, 20, FontStyle.Bold, GraphicsUnit.Pixel), new SolidBrush(Color.FromArgb(0, 0, 0)), titleRect, new StringFormat());

@siriussynoptek

In the code sample that you have shared, you need to set the font "Proxima-Nova” instance. You need to install the font on your end too.

Thank you for given solution.

We are using azure web app and there is no facility available to install the fonts. Kindly suggest how can we achieve this using font file or live font URL. We have tried below code snippet but didn’t get font effect. Here, Proxima-Nova-Reg.ttf file is stored at “E:\Publish_Web_Internal_API\wwwroot\HTML Templates\Base Template\fonts” location.

FontSettings.SetFontsFolder(“E:\Publish_Web_Internal_API\wwwroot\HTML Templates\Base Template\fonts”);
FontSettings.UpdateFonts();
RectangleF titleRect = new RectangleF(24, 90, 600, 68);
graphics.DrawString(“This is Proxima-Nova font.”, new Font(“Proxima-Nova-Reg”, 20, FontStyle.Bold, GraphicsUnit.Pixel), new SolidBrush(Color.FromArgb(0, 0, 0)), titleRect, new StringFormat());

@siriussynoptek

Can you please possibly try the font mechanisms used in following documentation article. It refers to a font file that is not installed but is available somewhere on disk and that is referred.

Hi mudassir,

I have checked link shared by you and try to implement code. I have set font name as “testing” in drawstring method and there is no such font having name “testing” in either font folder(E:\RenderHTML\RenderHTML\fonts) or in default font folder (C:\Windows\Fonts). So in which font my output is displaying? How FontSetting is working? Is it possible to set font weight in Aspose.imaging? How can i cross verify that output image font is actual one that i have set or not? Please suggest.
I have attached sample application for your reference.

RenderHTML.zip (4.9 MB)

@siriussynoptek

Can you please explain this.

By font weight, do you mean setting the font size?

In sample application(attached in earlier post), I have drawn string by giving font name “testing” but no such font exist in application or in system default folder in that case my generated image(output.png) showing text “This image is created by Aspose.Imaging API” but this text is displaying in which font?

Font weight means the thickness or thinness of font not size of font.

@siriussynoptek

We are checking this on our end and will share the feedback with you as soon as possible.

Hi mudassir,

Is there any undate?

@siriussynoptek

You may please need to specify font name and not font file. Please try using following sample code:

graphics.DrawString("Proxima Nova Rg - right", new Aspose.Imaging.Font("Proxima Nova Rg", 16), brush,new Aspose.Imaging.PointF(50, 100));

Hi mudassir,

Yes, It is correct that we need to specify font name but what if we specify wrong font name. In case of wrong font name, in which font output will be generated?

@siriussynoptek
You may use

FontSettings.DefaultFontName = "User-specified default font name";
FontSettings.GetSystemAlternativeFont = false;

to specify your preferred default font for such case.