Hello,
I am trying to change the font from Arial to Franklin Gothic Book in Word
I am trying to use:
FontSettings FontSettings = new FontSettings();
FontSettings.SetFontSubstitutes("MS Gothic", new string[] { "Arial Unicode MS" });
Get the error message: Fontsettings does not contain a definition for SetFontSubstitutes Are u missing using directive or assembly reference?
Which version of Aspose.Word should be used?
Thanks
kshah05
@kshah05 can you please share with us the version of Aspose.Words API that are you using.
Additionally, please check our official documentation about FontSubstitutionSettings class there we shoe a detailed example about how to access a document’s system font source and set font substitutes using the latest version of the API.
I am using Aspose.Words(22.12.0)
Is that correct?
@kshah05 Please note that when using the FontSubstitutionSettings
class, it allows you to specify a replacement font in case the original font used in the document is not available in your system. However, if you want to specifically replace a particular font in the document with another font, you can refer to the solution provided in this post.
The solution in the post demonstrates how to replace a specific font name, such as “Arial”, with another font name, such as “Segoe UI”, in the document. You can follow the code snippet provided in the post to achieve this specific font replacement.
Please let us know if you have any further questions or if there’s anything else we can assist you with.
I reviewed the post : How to change enter document Font Name to "SegoeUI" - #4 by alexey.noskov
Is there an option to replace the font with : Franklin Gothic Book
This font is not available on C:\Windows\Fonts…
I am installing the font on my local project folder. How do I get the font from local project folder and replace it in Aspose Document
@kshah05 you can set from where the font is loaded using the following piece of code, I also added an implementation of the IWarningCallback
interface to help you to detect if a font substitution was made:
string filePath = @"C:\Temp\input.docx";
string outputPdfPath = @"C:\Temp\output.pdf";
string _winFontFolder = @"C:\Windows\Fonts";
string _fontFolder = @"C:\Temp\fonts";
FontSettings.DefaultInstance.SetFontsFolders(new[] { _winFontFolder, _fontFolder }, true);
Aspose.Words.Document wordDoc = new Aspose.Words.Document(filePath, new Aspose.Words.Loading.LoadOptions
{
WarningCallback = new IssueCallBack()
});
wordDoc.FontSettings = Aspose.Words.Fonts.FontSettings.DefaultInstance;
public class IssueCallBack : IWarningCallback
{
public void Warning(WarningInfo info)
{
Console.WriteLine($"{ info.Description}");
}
}
Additionally, please notice that you can set any font in the document and it will be configured in the document even if the font is not available in your system, when you really need the font available is at the moment to render the document (Aspose.Words render the document when it is converted to any of the fixed document formats available, for example PDF).