How to specify font

I have updated SpecifyDefaultFontWhenRendering class(Aspose.Words.Examples.CSharp) as below.

class SpecifyDefaultFontWhenRendering
    public static void Run()
        // ExStart:SpecifyDefaultFontWhenRendering
        // The path to the documents directory.
        // string dataDir = RunExamples.GetDataDir_RenderingAndPrinting();
        string dataDir;

        // Document doc = new Document(dataDir + "Rendering.doc");
        Document doc = new Document("hgs_pop_font.docx");

        FontSettings FontSettings = new FontSettings();

        // If the default font defined here cannot be found during rendering then the closest font on the machine is used instead.
        FontSettings.DefaultFontName = "Arial Unicode MS";
        // Set font settings
        doc.FontSettings = FontSettings;
        // dataDir = dataDir + "Rendering.SetDefaultFont_out.pdf";
        dataDir = "hgs_pop_font_out.pdf";
        // Now the set default font is used in place of any missing fonts during any rendering calls.
        // ExEnd:SpecifyDefaultFontWhenRendering 
        Console.WriteLine("\nDefault font is setup during rendering.\nFile saved at " + dataDir);


I have created word file(hgs_pop_font.docx) in PC1 which has been installed HGS創英角ポップ体 font.
I run the program in PC2 which has NOT been insalled HGS創英角ポップ体 font.
I expected Arial Unicode MS is used, but Meiryo(closest font?) seems to be used in the pdf.

Is the font priority “actual font”(HGS創英角ポップ体) > “closest font”(Meiryo) > “default font”(Arial Unicode MS)?
I would like the font priorty as “actual font”(HGS創英角ポップ体) > “default font”(Arial Unicode MS) > “closest font”(Meiryo).
Do you have any solution?

Hi there,

Thanks for your inquiry. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-15323. You will be notified via this forum thread once this issue is resolved. We apologize for your inconvenience.

Please use FontSettings.SetFontSubstitutes method as a workaround of this issue. Hope this helps you.

Document doc = new Document(MyDir + "hgs_pop_font.docx");
FontSettings FontSettings = new FontSettings();
FontSettings.SetFontSubstitutes("HGS創英角ポップ体", new string[] { "Arial Unicode MS" });
doc.FontSettings = FontSettings;
doc.Save(MyDir + "output.pdf");


Thanks for your patience. It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue (WORDSNET-15323) as ‘Not a Bug’.

Please note that now font substitution mechanism will override the FontSettings.DefaultFontName in cases when FontInfo for the missing font is available in the document. FontSettings.DefaultFontName will be used only in cases when there are no FontInfo for the missing font. We have updated the article about font availability and substitution. Please read the detail from here:
Font Availability and Substitution

Best Regards,
Tahir Manzoor

Thank you for your support.

I still don’t get the relation between font substitution mechanizm and FontInfo. (5.4 KB)
Rendering.MissingFontNotification_out.pdf (28.3 KB)

Could you explain concretely why FontSettings.DefaultFontName = “MS Gothic” is unavailable in my environment.

Screen shot of console.
console_screenshot.png (8.3 KB)

This is my code.

class ReceiveNotificationsOfFont 
        public static void Run()
            // ExStart:ReceiveNotificationsOfFonts 
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_RenderingAndPrinting(); 

            Document doc = new Document(dataDir + "Rendering.doc");

            FontInfoCollection fonts = doc.FontInfos;
            int fontIndex = 1;

            // The fonts info extracted from this document does not necessarily mean that the fonts themselves are
            // used in the document. If a font is present but not used then most likely they were referenced at some time
            // and then removed from the Document.
            foreach (FontInfo info in fonts)
                // Print out some important details about the font.
                Console.WriteLine("Font #{0}", fontIndex);
                Console.WriteLine("Name: {0}", info.Name);
                Console.WriteLine("IsTrueType: {0}", info.IsTrueType);

            FontSettings FontSettings = new FontSettings();          

            // We can choose the default font to use in the case of any missing fonts.
            FontSettings.DefaultFontName = "MS Gothic";

            // For testing we will set Aspose.Words to look for fonts only in a folder which doesn't exist. Since Aspose.Words won't
            // Find any fonts in the specified directory, then during rendering the fonts in the document will be subsuited with the default
            // Font specified under FontSettings.DefaultFontName. We can pick up on this subsuition using our callback.
            //FontSettings.SetFontsFolder(string.Empty, false);

            // Create a new class implementing IWarningCallback which collect any warnings produced during document save.
            HandleDocumentWarnings callback = new HandleDocumentWarnings();

            doc.WarningCallback = callback;
            // Set font settings
            doc.FontSettings = FontSettings;
            string path = dataDir + "Rendering.MissingFontNotification_out.pdf";
            // Pass the save options along with the save path to the save method.
            // ExEnd:ReceiveNotificationsOfFonts 
            Console.WriteLine("\nReceive notifications of font substitutions by using IWarningCallback processed.\nFile saved at " + path);

            //ReceiveWarningNotification(doc, dataDir);
        private static void ReceiveWarningNotification(Document doc, string dataDir)
            // ExStart:ReceiveWarningNotification 
            // When you call UpdatePageLayout the document is rendered in memory. Any warnings that occured during rendering
            // Are stored until the document save and then sent to the appropriate WarningCallback.

            // Create a new class implementing IWarningCallback and assign it to the PdfSaveOptions class.
            HandleDocumentWarnings callback = new HandleDocumentWarnings();

            doc.WarningCallback = callback;
            dataDir = dataDir + "Rendering.FontsNotificationUpdatePageLayout_out.pdf";
            // Even though the document was rendered previously, any save warnings are notified to the user during document save.
            // ExEnd:ReceiveWarningNotification  
        // ExStart:HandleDocumentWarnings
        public class HandleDocumentWarnings : IWarningCallback
            /// <summary>
            /// Our callback only needs to implement the "Warning" method. This method is called whenever there is a
            /// Potential issue during document procssing. The callback can be set to listen for warnings generated during document
            /// Load and/or document save.
            /// </summary>
            public void Warning(WarningInfo info)
                // We are only interested in fonts being substituted.
                if (info.WarningType == WarningType.FontSubstitution)
                    Console.WriteLine("Font substitution: " + info.Description);
        // ExEnd:HandleDocumentWarnings


Thanks for your your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does. Aspose.Words evaluates all related fields in FontInfo (Panose, Sig etc) and finds the closest match among the available font sources. Please remove “Meiryo” font from your font sources and execute the same code to check this behavior.

Thank you for support.
I cannot remove “Meiryo” font from my PC because it is system font. You mean the most suitable font overrides FontSettings.DefaultFontName. is that right? I may need the new mode that FontSettings.DefaultFontName overrides the most suitable font.
Thank you.


Thanks for your your inquiry. Yes, your understanding is correct. If the most suitable font is available in font sources, it will override the FontSettings.DefaultFontName.

Please check the members of FontSettings class. You may achieve your requirements using FontSettings.SetFontSubstitutes and FontSettings.AddFontSubstitutes methods. Hope this helps you .