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

Free Support Forum - aspose.com

Loading fonts from a Font Folder

i am using the below code
` FontSettings fontSettings = new FontSettings();
fontSettings.setDefaultFontName(“Arial”);
fontSettings.setFontsFolder(MyDir, false);
doc.setFontSettings(fontSettings);
doc.setWarningCallback(new HandleDocumentWarnings()); ’

I am convert the file from .docx to .pdf format but in this conversion, if any font format is not available or not supported by aspose then it search the fonts in the font folder
but if i use the above code then it always search the all fonts in set font folder only if not found then print it from best possible match fonts from Folder only.
it give warning like

Font substitution : Font ‘Calibri’ has not been found. Using ‘Xephyr Leftalic’ font instead. Reason: closest match according to font info from the document.
Font substitution : Font ‘Algerian’ has not been found. Using ‘Xephyr Leftalic’ font instead. Reason: closest match according to font info from the document.
Font substitution : Font ‘Bauhaus 93’ has not been found. Using ‘Xephyr Leftalic’ font instead. Reason: closest match according to font info from the document.
Font substitution : Font ‘Verdana’ has not been found. Using ‘Xephyr Leftalic’ font instead. Reason: closest match according to font info from the document.
Font substitution : Font ‘Times New Roman’ has not been found. Using ‘Xephyr Leftalic’ font instead. Reason: closest match according to font info from the document.
Font substitution : Font ‘Arial’ has not been found. Using ‘Xephyr Leftalic’ font instead. Reason: closest match according to font info from the document.

on more question, what is use of true/ false in fontSettings.setFontsFolder(MyDir, false);

@ramveer

Thanks for your inquiry. Following code example demonstrates how to set Aspose.Words to look for TrueType fonts in system folders as well as a custom defined folder when scanning for fonts.

ArrayList<FolderFontSource> fontSources = new ArrayList(Arrays.asList(FontSettings.getDefaultInstance().getFontsSources()));
FolderFontSource folderFontSource = new FolderFontSource("c:\\temp\\", true);

fontSources.add(folderFontSource);
FontSourceBase[] updatedFontSources = (FontSourceBase[]) fontSources.toArray(new FontSourceBase[fontSources.size()]);
FontSettings.getDefaultInstance().setFontsSources(updatedFontSources); 

When this paramemer is true, Aspose.Words’ rendering engine scans the specified folders for fonts recursively.

This is not answer of my question. whatever answer posted it is totally different from my question.
One more question–> if i not set any font during conversion from doc to PDF then from where aspose get the font details. is aspose have any list of supported fonts .

@ramveer,

You are using FontSettings.setFontsFolder method. In this case, Aspose.Words looks for fonts in the folder that you specify in this method. If you want to use fonts from Windows\Fonts and custom font’s folder, you need to use the code shared in my previuos post.

There is no need to set the font’s folder if your document is using Windows fonts. The answer of your query is well explained in the following article. Please read it.
Font Availability and Substitution

Please let us know if you have any more queries.

Below is my code as per your suggestion -

ArrayList fontSources = new ArrayList();
String fontDir = ConfigLocation.getXDOFontDir();
FolderFontSource folder1 = new FolderFontSource(fontDir,false);
fontSources.add(folder1);
FontSourceBase[] fontSourceBase = (FontSourceBase[])fontSources.toArray(new FontSourceBase[fontSources.size()]);
FontSettings fontSettings = new FontSettings();
fontSettings.setDefaultFontName(“Arial”);
fontSettings.setFontsSources(fontSourceBase);

        doc.setWarningCallback(createWarningCallback());
        doc.setFontSettings(fontSettings); 

still it take the fonts only from set fonts directory(fontDir) not from Windows\fonts.

@ramveer

Thanks for your inquiry. In your code, you are not getting font source and update it with custom font’s folder. The following line of code is missing.

ArrayList<FolderFontSource> fontSources = new ArrayList(Arrays.asList(FontSettings.getDefaultInstance().getFontsSources()));

If you do not want to use the default instance of font setting, you need to add one more font source for “Windows/Fonts” folder.